2016-09-07 89 views
0

這是關於Laravel 5.3.6

我能夠成功登錄,我可以在登錄後檢查身份驗證用戶。我可以顯示Auth::guard()具有當前用戶對象的確切位置。以下是詳細信息。 Auth :: user()在5.3.6中爲空?

  1. 進入登錄控制器
  2. 轉到AuthenticatesUsers特質
  3. 轉到sendLoginResponse方法。用戶成功到達此處,因爲用戶已通過身份驗證。

在這裏,我可以檢查$this->guard()->user()擁有當前用戶的價值。但是,當控制達到角色控制器....我試圖訪問它像這樣dd(Auth::guard());和值爲空。我還在角色控制器中添加了以下參考。

use Illuminate\Support\Facades\Auth; 

下面是我的角色控制器的路線。

Route::group(['middleware' => ['auth']], function() { 
    Route::get('/Roles',    
     array (
      'uses' => 'Website\Role\[email protected]',  
      'as' => 'Roles' 
     ) 
    ); 
}); 

您在Laravel 5.3.6中遇到過這種問題嗎?

\Auth::guard()的輸出如下。

SessionGuard {#162 ▼ 
    #name: "web" 
    #lastAttempted: null 
    #viaRemember: false 
    #session: Store {#165 ▶} 
    #cookie: CookieJar {#167 ▶} 
    #request: Request {#40 ▶} 
    #events: Dispatcher {#5 ▶} 
    #loggedOut: false 
    #tokenRetrievalAttempted: false 
    #user: null 
    #provider: EloquentUserProvider {#158 ▶} 
} 
+0

你覆蓋在登錄控制器的任何方法,如果是的話,請張貼 – msonowal

+0

不,我沒有覆蓋任何方法。 – Pankaj

+0

完整的dd(Auth :: guard());爲空或只有「用戶」部分,您可以請張貼控制器嗎?在你到達控制器路由之前,dd(Auth :: guard()); geves你收集? –

回答

0

Kernel.php文件就像下面

protected $middleware = [ 
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, 
]; 

protected $middlewareGroups = [ 
    'web' => [ 
     \App\Http\Middleware\EncryptCookies::class, 
     \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 
     \Illuminate\Session\Middleware\StartSession::class, 
     \Illuminate\View\Middleware\ShareErrorsFromSession::class, 
     \App\Http\Middleware\VerifyCsrfToken::class, 
     \Illuminate\Routing\Middleware\SubstituteBindings::class, 
    ], 

    'api' => [ 
     'throttle:60,1', 
     'bindings', 
    ], 
]; 

我改變了它下面喜歡。

protected $middleware = [ 
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, 
    \App\Http\Middleware\EncryptCookies::class, 
    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 
    \Illuminate\Session\Middleware\StartSession::class, 
    \Illuminate\View\Middleware\ShareErrorsFromSession::class, 
    \App\Http\Middleware\VerifyCsrfToken::class, 
]; 

protected $middlewareGroups = [ 
    'web' => [ 
     \Illuminate\Routing\Middleware\SubstituteBindings::class, 
    ], 

    'api' => [ 
     'throttle:60,1', 
     'bindings', 
    ], 
]; 
相關問題