Home > OS >  Laravel 8.x: redirect after Login to previous location, with all Input data reinserted
Laravel 8.x: redirect after Login to previous location, with all Input data reinserted

Time:07-22

I'm trying to build an app with Laravel that allows users to book flights with several locations included.

For autentication I'm using the laravel/ui package.

To complete the booking, if the user is not logged, he's redirected to login form and if the credentials are valid he returns to the previous page.

The problem is once the user returns back, after login, the data passed previously with the POST request at that page do not exist anymore.

I put a flowchart to explain better what I would like to do:

https://i.stack.imgur.com/JeF3e.jpg

So, what should I do to reload that page, with the previous POST values?

CodePudding user response:

In that case you should redirect user back using withInput(), eg.:

return back()->withInput();

Here you can find a more detailed explanation: https://laravel.com/docs/8.x/responses#redirecting-with-input

CodePudding user response:

You could make a temp table to save this data before redirecting the user to log in with a unique value in the session held in both the new user row and the previous temp table.

Then after redirection load the page with user temp data in the temp table through that key.

It would be nice if you do a corn job to delete these temp data daily.

  • Related