zouboulba
zouboulba

Reputation: 1

Laravel - i can't update user info

I cannot modify the user's information. when i click on the button, nothing happens. No change, and no error message.

the controller

public function update(Request $request)
{


    $this->validate($request, [
        'prenom' => 'required|min:5',
        'nom' => 'required|min:5',
        'pseudo' => 'required|min:5',
        'email' => 'required|min:5',
    ]);


    $id = auth()->id();
    $user = User::find($id);

    $user->prenom = $request->input('prenom');
    $user->nom = $request->input('nom');
    $user->pseudo = $request->input('pseudo');
    $user->email = $request->input('prenom');
    $user->save($request->all());


    return redirect()->route('user.account');
}



    

Upvotes: 0

Views: 135

Answers (1)

Mikael Dalholm
Mikael Dalholm

Reputation: 131

First of all if the user is signed in, you will have the user in the request and can access it with $request->user();

Second, i would update the user with this $request->user()->update($request->all())

Make sure that you have the fillables on the user model

$this->validate($request, [
    'prenom' => 'required|min:5',
    'nom' => 'required|min:5',
    'pseudo' => 'required|min:5',
    'email' => 'required|min:5',
]);

$request->user()->update($request->all());

return redirect()->route('user.account');

Upvotes: 2

Related Questions