我創建了一個名爲中間件管理員Laravel 5.3:建立管理中間件
public function handle($request, Closure $next)
{
if (Auth::guard($guard)->check()) {
if (Auth::user()->isAdmin())
return redirect('/list_host');
else {
// return $next($request);
return redirect('/home');
}
}
}
IsAdmin看起來是這樣的:
public function isAdmin()
{
return $this->is_admin;
}
而且他們我要檢查,如果用戶登錄並具有管理 - 權利。 我也把它添加到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\Auth\Middleware\Admin::class,
];
然後,我用它在路線/ web.php
Route::get('/list_hosts', function() {
return view('/list_hosts');
})->middleware('admin');
遺憾的是還沒有管理員可以查看站點。有什麼建議麼?
系統如何知道用戶是否具有管理權限? – Onix
相關:http://stackoverflow.com/questions/34614753/can-anyone-explain-laravel-5-2-multi-auth-with-example –
是不是你有機會陷入與重定向的無限循環?中間件永遠將管理員重定向到自己,不是嗎? –