Reputation: 21
I get an error
Call to undefined method Illuminate\Auth\GenericUser::update()
here is code
$user = Auth::user();
$user->name = 'name';
$user->update();
return redirect()->back();
Upvotes: 1
Views: 10943
Reputation: 163748
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');
}
Upvotes: 1
Reputation: 10179
You need update user from User model and then update Auth onject
$user = User::find(Auth::user()->id);
$user->name = 'name';
$user->save();
Update Auth:
Auth::setUser($user);
Upvotes: 2