我有我的身份驗證登錄時這樣做。Auth不堅持在Laravel 5.2
if (Auth::attempt($userdata)) {
dd(Auth::user()); //this shows the user just fine,
//which proves that the auth driver is working.
return redirect()->intended('dashboard');
}
但是,在重定向到儀表板之後。看起來auth不是持久的。如果我做dd(Auth::user())
甚至只是Auth::check()
它會返回null。
,路線如下:
Route::group(['middleware' => ['web']], function() {
Route::get('test',function(){
dd(Auth::user()); //returns null
echo Auth::user()->name; // returns Trying to get property of non-object
});
});
我在做什麼錯?
關於這個奇怪的事情是,昨晚它工作。它有點神奇地停止工作。
如果您在'attempt'之後'dd',則會話不一定會持續。如果你只是返回一個空字符串作爲響應而不是你的重定向,並且手動進入測試路由,那麼會發生什麼? – Dencker
另外,不是'attempt',你可以通過調用'login'來進一步調試,並強制登錄一個用戶。這至少會繞開實際授權的潛在問題。這很可能是cookie或會話問題:) – Dencker