Reputation: 9416
As the title says - I'm trying to redirect back to previous page, with input data, like this:
return Redirect::back()->withInput();
It works as intended for regular input, but not for files! Is there a workaround for this? So that after the redirect, the previous file is selected again.
Upvotes: 10
Views: 16755
Reputation: 481
If you make with form like
Form::text("name",null);
it would be work, try it :)
Upvotes: 1
Reputation: 1884
I would go for a java-script approach, just validate input data in browser using java-script if input is good, let them submit the form. just an suggestion..!!
Upvotes: 0
Reputation: 87789
It won't work.
When you redirect something in Laravel it stores $_POST and $_GET in Session to get you data back in the next request. Files comes in a special PHP global var, $_FILES, because they are not really in memory, they are in disk and just some info about them in memory.
Storing those files in Session could cost too much in resources, imagine storing them in the Session you store in database... Yeah, Laravel or Symfony could create a layer to deal with it, looks easy at first sight, but looks like they just decided not to.
So, IMO, if you need them in the next request, move them to a temporary area and Session::put() the info about them, so you can just Session::get() them in the next request.
Upvotes: 6
Reputation: 452
This may work:
return Redirect::back()->with('file', Input::file('file_name');
Upvotes: 1
Reputation: 9416
As mentioned here, there is no straight forward way to do this. A valuable solution might be, saving the file somewhere, upon the upload, and then populating your form, after the redirect, with an additional input field, that contains the information about your previously uploaded file. That way you'll be able to decide on the server side, wether to take the old one (in case there wasn't a new file uploaded) or the new one.
Upvotes: 1