我试图登录到我的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版本? –