Laravel 中的 FatalThrowableError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45257624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:21:30 来源:igfitidea点击:
FatalThrowableError in Laravel
提问by Rafael
I get an error
我收到一个错误
Call to undefined method Illuminate\Auth\GenericUser::update()
调用未定义的方法 Illuminate\Auth\GenericUser::update()
here is code
这是代码
$user = Auth::user();
$user->name = 'name';
$user->update();
return redirect()->back();
采纳答案by Govind Samrow
You need update user from Usermodel and then update Authonject
您需要从User模型更新用户,然后更新Authonject
$user = User::find(Auth::user()->id);
$user->name = 'name';
$user->save();
Update Auth:
更新验证:
Auth::setUser($user);
回答by Alexey Mezenin
You should check if user is authenticated, then you can update name:
您应该检查用户是否通过身份验证,然后您可以更新名称:
if (auth()->check()) {
auth()->user()->update(['name' => 'name']);
} else {
dd('User is not authenticated');
}