I have a profile view where i would like to update users profile.
my Controller:
public function update(Request $request, User $user)
{
$validatedData = $request->validate([
'name' => 'required',
'email' =>'required|email',
'key' => 'required'
]);
// dd($user);
$user->update($validatedData);
// User::whereId($user->id)->update($validatedData);
return back()->with('flash', 'Successfully updated profile.');
}
I'm injecting a model's instance into my route. When i dd($user)
i get the current user instance.
Now i would like to update the user with the validatedData. But unfortunately this $user->update($validatedData);
is not working. I don't understand why...
This User::whereId($user->id)->update($validatedData);
is working but it feels very strange to call on user
the user->id
.