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:
So, what should I do to reload that page, with the previous POST values?
In that case you should redirect user back using withInput(), eg.:
Here you can find a more detailed explanation: https://laravel.com/docs/8.x/responses#redirecting-with-input
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.
I solved adding GET method to the page to book the flight, then I pass the input data from the middleware as route params to the login form. After the login form is submitted, if the user log successfully, that data are flashed to the session and are available after redirect to the previous page. I think is not the best solution because the data are shown in the URL in login page, but it works.