我试图登录我的Laravel应用程序,我面临一些奇怪的问题,我似乎不知道为什么。
我有一个功能
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":"benlong@biossusa.com","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?
如何继续进行调试?
我现在正在接受任何建议。
任何提示/建议/帮助都将非常感谢!
答案 0 :(得分:-2)
您可以使用Auth :: user() - >用户名来获取当前用户的用户名值。