2016-01-20 88 views
1

我做了一個簡單的登錄表單。我登錄我的用戶有:重定向|後,Auth會話被終止laravel 5.2

Auth::loginUsingId($user->id, true); 

但是,當我將用戶重定向到ClientController我重定向到登錄表單,將驗證會話不persitent。

return redirect()->action('[email protected]'); 

我的路線:

Route::group(['middleware' => 'web'], function() { 
    Route::get('/', '[email protected]'); 
    Route::post('/', '[email protected]'); 
}); 
Route::group(['prefix' => 'admin', 'middleware' => 'web'], function() { 
    Route::get('/', '[email protected]'); 
}); 

Route::group(['prefix' => 'client', 'middleware' => ['auth', 'web']], function() { 
    Route::get('/', '[email protected]'); 
}); 

回答

1

web中間件需要,因爲web中間件負責引導你的會話auth中間件之前一命嗚呼開關使用的順序是這樣的:

Route::group(['prefix' => 'client', 'middleware' => ['web', 'auth']], function() { 
    Route::get('/', '[email protected]'); 
}); 

然而,當我們在這個問題上,你可以窩路組另一路由組中,從而防止這樣的錯誤在未來,我只想建議築巢一切裏面的web這樣的中間件:

Route::group(['middleware' => 'web'], function() { 
    Route::get('/', '[email protected]'); 
    Route::post('/', '[email protected]'); 

    Route::group(['prefix' => 'admin'], function() { 
     Route::get('/', '[email protected]'); 
    }); 

    Route::group(['prefix' => 'client', 'middleware' => 'auth'], function() { 
     Route::get('/', '[email protected]'); 
    }); 
});