2017-08-01 153 views
0

我面临Auth问题,我有管理中间件和处理函数,但Auth::check总是返回false。看起来像用户会话不存在。Auth :: check()返回false Laravel 5.2

我认为问题出现在/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'); 
    } 
} 

什么想法?

感谢

+0

是否使用自己的身份验证系统或Laravel的一个? –

+0

自定义Laravel Auth,我刚添加了我的Admin中间件。在本地服务器上,一切正常。这个问题只在生产服务器上。 –

+0

@zm_fans请显示您的中间件详细信息 –

回答

0

或者你可以使用类似

//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

相关问题