错误“目标类[Wazawaza2Middleware]不存在。”

时间:2020-06-10 01:08:47

标签: laravel

我想在laravel中使用中间件,但要说明一下。 enter image description here

我认为我的代码是正确的。

Wazawaza2Middleware.php

<?php

namespace App\Http\Middleware;
use Illuminate\Support\Facades\Auth;

use Closure;

class Wazawaza2Middleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(Auth::check()){
            return $next($request);
        }else{
            return view('auth.login');
        }
    }
}

web.php

use App\Http\Middleware\Wazawaza2Middleware;

Route::get('topde', 'ReviewController@top')->middleware('Wazawaza2Middleware::class');

Kernel.php

    protected $routeMiddleware = [
      .
      .
      .
    'wazawaza2' =>
        \App\Http\Middleware\Wazawaza2Middleware::class,
    ];

1 个答案:

答案 0 :(得分:0)

您的web.php中存在错误,应为:

use App\Http\Middleware\Wazawaza2Middleware;

Route::get('topde', 'ReviewController@top')->middleware(Wazawaza2Middleware::class);

OR(因为您要给它起别名)

Route::get('topde', 'ReviewController@top')->middleware('wazawaza2');