forexknight forexknight - 24 days ago 6
PHP Question

Laravel validation resets inputs value

I am wondering how to pass to inputs old value if user fails the laravel validation. I've tried to use:
Example:

{{ Request::old('mail') }}

And:
{{ old('mail') }}

I think that if user fails laravel validation input values are deleted.
Anyone has some idea to solve the problem?

Answer

With laravel 5.2 If you’re redirecting back to the form, a really useful method is withInput():

return redirect()->back()->withInput();

This method has no parameters and what it does is saves the old form values into Session. Then in the form you can use function old($key) to retrieve those values for every field – that would be a separate topic about the Forms.