[英]Auth::check() return false Laravel 5.2
我遇到了Auth問題,我內部具有管理中間件和句柄功能,但Auth::check
始終返回false。 似乎用戶會話不存在。
我以為問題出在/storage
和/bootstrap/cache
權限中,但是當我為這些文件夾設置777
,問題仍然相同。 會話文件夾不為空。
我試圖清除緩存。
我的管理員中間件:
public function handle($request, Closure $next)
{
//check the proper role
if (Auth::check() && Auth::user()->isAdmin()) {
return $next($request);
}
else {
return response()->view('auth.forbidden')->header('Content-Type', 'text/html');
}
}
有任何想法嗎?
謝謝
或者,您可以使用類似
//check the proper role
$user = $request->user();
if ($user && $user->isAdmin()) {
return $next($request);
}
else {
return response()->view('auth.forbidden')->header('Content-Type', 'text/html');
}
用戶登錄並且isAdmin將正常工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.