Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 881
Fokwa Best Avatar asked Mar 15 '23 12:03

Fokwa Best


1 Answers

You must follow this approach:

<input type="text" name="name" value="{{ old('name', $user->name) }}" id="name"  class="form-control"/>
like image 145
user2094178 Avatar answered Mar 17 '23 05:03

user2094178