1

In my application I currently have a dashboard, this dashboard accepts a list of GET parameters to do things like filter, and for pagination.

An example of my url is this

http://mysite.local/dashboard?filters=true&search=&optIn=on&dateFrom=&dateTo=&submit=Search&page=3

On my dashboard I can then a link which will take me to a users information, so I can edit it. Inside my users page I can have a button that just has {{ url()->previous() }} inside it, to go back to my dashboard and keep all of my GET parameters.

The issue is the users page has the ability to update, which sends a request to a POST controller, then returns back to the users page with a success or error message, and this can be done and updated as many times as possible, so once this is done the url()->previous is now the users page, and i lose the dashboard url with all of my parameters.

I need to be able to keep the dashboard url with all of the GET parameters so that once the user is done on the users page, they can always get back to the dashboard with their filters and page.

Whats the best way to achieve this?

S_R
  • 1,818
  • 4
  • 27
  • 63
  • Possible duplicate of [How to redirect back to form with input - Laravel 5](https://stackoverflow.com/questions/31081644/how-to-redirect-back-to-form-with-input-laravel-5) – Gaurav Dave Jun 05 '18 at 11:58
  • You could store the filters in a session and repopulate the filters when then user goes back to the dashboard. – M. Eriksson Jun 05 '18 at 11:59
  • Possible duplicate of [Laravel Request getting current path with query string](https://stackoverflow.com/questions/31555494/laravel-request-getting-current-path-with-query-string) – online Thomas Jun 05 '18 at 12:04
  • @GauravDave Have you read the question? This is not a duplicate at all... – Douwe de Haan Jun 05 '18 at 12:06
  • You have the dashboard URL on dashboard page (with query string) can you save that in global and use in every view – DsRaj Jun 05 '18 at 12:10

2 Answers2

0

If you plan on doing url()->previous() on the view, then you'd have to work around with fetching the parameters and aggregating it to the url.

You can, aswell, store it in the Session but then again, you would have to validate the Session's content everytime.

Why don't you work it on a controller/route and manipulate it?

If you want to have the inputs filled, try this:

https://laravel.com/docs/5.6/requests#old-input

You can see more information here on urls:

https://laravel.com/docs/5.6/urls

abr
  • 2,071
  • 22
  • 38
  • _"you would have to validate the Session's content everytime"_ - You validate it when you store the data, which you would need to do anyway before using it. No extra validation needed. – M. Eriksson Jun 05 '18 at 12:37
0

I think the request input was the correct way about it, this is how I've done it.

I've attached a hidden input on my form which detects whether or not a previous URL is being passed back from the form and if not, use the previous page URL.

{{ Form::hidden('previous_url',  old('previous_url', url()->previous()) )}}

I then made sure the input is being passed back from the controller

return redirect()->back()->withInput(Input::all());

And then finally I placed the same input code in the <a href=""> like so

<a href="{{old('previous_url', url()->previous())}}" class="back-button"><i class="far fa-arrow-alt-circle-left"></i>Back</a>

Now the a tag will always contain the URL from the previous page when I first load the users page

S_R
  • 1,818
  • 4
  • 27
  • 63