I'm using a form in Laravel 5.1 to post some text and to upload a file. It looks like this (simplified version):
{!! Form::open(array('url' => 'foo/bar')) !!}
{!! Form::text('image_name') !!}
{!! Form::file('image') !!}
{!! Form::submit('Submit!') !!}
{!! Form::close() !!}
The textfield is required, so I added a $validator
in my controller. If validation fails, the user is redirected back to the form. I use the withInput()
method to repopulate the form so that the user doesn't have to fill it in again:
if ($validator->fails()) {
return redirect()->back()->withInput();
}
This will get the old input back for textfields, dropdowns etc. But if the user has uploaded a file, the file selection is gone when validation fails and has to be selected again. Is there any way in Laravel to remember file selection as old input?
Thanks!