我試圖登錄到我的Laravel應用程序,並且我遇到了一些我似乎不知道爲什麼的奇怪問題。Auth :: user()在重定向後返回NULL
我有一個函數
public function postLogin(){
$input = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
$rules = array(
'username' => 'Required',
'password' => 'Required'
);
$validator = Validator::make($input, $rules);
if ($validator->passes()){
// Try to log the user in.
if (Auth::attempt($input)){
$input['status'] = 1;
//return Auth::user();
return Redirect::to('/dashboard')->with('success', 'You have logged in successfully');
}
else{
return Redirect::to('/')->withErrors(array('password' => 'Password invalid'))->withInput(Input::except('password'));
}
}
return Redirect::to('/')->withErrors($validator)->withInput(Input::except('password'));
}
當我做return Auth::user();
我得到了我的用戶打印出來。
{"id":18,"username":"bheng","email":"[email protected]","first_name":"benlong","last_name":"Heng","updated_at":"2016-10-29 15:05:36","created_at":"2014-06-27 19:58:53","status":1,"timezone":"US\/Eastern","lock_version":10,"remember_token":"s2ogIchC7KIfduiFslKwUwW2IYMgcFaDESSUd0UMcPwBYRIxZmpRbqkKfBWt"}
然後,我把線代替
return Redirect::to('/dashboard')->with('success', 'You have logged in successfully');
我重定向到/dashboard
頁面,dashboard.blade.php
得到裝入該錯誤
試圖讓非對象的屬性
然後,我檢查我的Auth::user()
而在我dashboard.blade.php
它返回NULL
問題
爲什麼突然就返回null
?
我應該檢查什麼? Session/Auth/Apache/Laravel?
如何進一步調試?
我打開此時的任何建議。
任何提示/建議/對此的幫助將非常感謝!
這似乎是一個會話問題。您是否使用單獨的前端或刀片視圖? – schellingerht
我正在使用刀片視圖。我如何檢查或測試我的會話? – ihue
你有哪個Laravel 4.xxx版本? –