创建中间件,但它不在Laravel 5.5中工作
我想为特定用户验证视图文件。我为此创建了中间件。以下是中间件的代码: -创建中间件,但它不在Laravel 5.5中工作
namespace App\Http\Middleware; use Closure;
use Illuminate\Support\Facades\Auth;
class ClientAuth
{
public function handle($request, Closure $next)
{
if(Auth::user() && Auth::user()->account_type==3)
{
return $next($request);
}
return redirect('/');
}
}
接下来,我在kernel.php文件中调用了'客户端'中间件。以下是代码: -
protected $routeMiddleware = [ 'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'admin' => \App\Http\Middleware\isAdmin::class,
'client' => \App\Http\Middleware\ClientAuth::class
];
然后,我已经在路由中调用了它。
Route::group(['middleware' => ['auth','client']], function() {
Route::get('clientdatabase',
'ClientDatabase\[email protected]');
});
这是行不通的。我哪里错了?
回答:
您的呼叫在路由中是错误的。 例如
Route::middleware(['auth','client'])->group(function() { Route::get('clientdatabase','ClientDatabase\[email protected]');
});
以上是 创建中间件,但它不在Laravel 5.5中工作 的全部内容, 来源链接: utcz.com/qa/261170.html