Fokwa Best
Fokwa Best

Reputation: 3515

How to repopulate a form with latest changes after validation failure during update in laravel 5

I am new to laravel 5. I have created a form to edit users info which is populated with information from the DB. After form validation if I get an error, I lose all the info I just modified, and the db info is restored.

My form field look like below:

 <input type="text" name="name" value="{{ $user->name }}" id="name"  class="form-control"/>

What I would like to see happen is this. If during edit the user clears off the users name from the field and make other changes on the different fields on my form. After a validation failure, I want his recent changes to stick and not the info from the database.

NB: Because of the nature of my form, I cannot bind a model to it.

Upvotes: 5

Views: 2360

Answers (1)

user2094178
user2094178

Reputation: 9454

You must follow this approach:

<input type="text" name="name" value="{{ old('name', $user->name) }}" id="name"  class="form-control"/>

Upvotes: 9

Related Questions