Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Redirect::withInput()

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.

like image 462
M K Avatar asked Dec 30 '13 00:12

M K


People also ask

How do I redirect back in laravel?

If you just want to redirect a user back to the previous page (the most common example - is to redirect back to the form page after data validation failed), you can use this: return redirect()->back();

How do I redirect back to original URL after successful login in laravel?

You may use Redirect::intended function. It will redirect the user to the URL they were trying to access before being caught by the authenticaton filter.


1 Answers

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.

like image 60
Antonio Carlos Ribeiro Avatar answered Sep 27 '22 23:09

Antonio Carlos Ribeiro