[英]Auth::check() return false Laravel 5.2
I am facing an issue with Auth, I have admin middleware and handle function inside, but Auth::check
always return false. 我遇到了Auth问题,我内部具有管理中间件和句柄功能,但
Auth::check
始终返回false。 Seems like user session doesn't exist. 似乎用户会话不存在。
I thought the problem was in permissions for /storage
and /bootstrap/cache
, but when I set up 777
for these folders the problem still the same. 我以为问题出在
/storage
和/bootstrap/cache
权限中,但是当我为这些文件夹设置777
,问题仍然相同。 Session folder is not empty. 会话文件夹不为空。
I have tried to clear cache. 我试图清除缓存。
My Admin Middleware: 我的管理员中间件:
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');
}
}
Any Ideas? 有任何想法吗?
Thanks 谢谢
alternatively you can use something like 或者,您可以使用类似
//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');
}
will work is user is logged in and isAdmin 用户登录并且isAdmin将正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.