2017-08-01 100 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

相關問題