Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DarkHarden's avatar

Url previous - moving between more pages

Hello,

I am a newbie here and I don't know how to set up moving between URL's right. Let's assume this example

/orders
/orders/edit/1
/orders/addNote/1

1. problem

Main page /orders has got a table with filter form in $_GET. You can go to detail of order from there /orders/edit/1.

Now you can use this for going back to orders:

<a href="{{ url()->previous() }}" class="btn btn-default">Back</a>

But, when form on edit site has errors, this href link returns me on same site /orders/edit/1

2. problem

Now, let's assume that we go from /orders?name=order_name to /orders/edit/1 and then we need to add note /orders/addNote/1 and go back to /orders?name=order_name. This will work only for last step (addNote -> edit) and then context is lost.

Is there any way how to do this right?

Thank you for any help

0 likes
8 replies
Snapey's avatar

After updating data, you redirect back to the same page or its parent.

For example, if you are on /orders and you click edit on an item, ypu might load /orders/edit/1

after posting data to that order, you finish with redirect('/orders') rather than previous

If you add a note, you know which order it was for so you can return to the specific order rather than the list of orders or previous

1 like
DarkHarden's avatar

@snapey Thank you for your answer. It will be right but there is a filter on orders page. And also, user can go to /orders/edit/1 from multiple routes like /stats/orders etc.

Go to filter and back
  • /orders?name=order_name
  • /orders/edit/1
  • and go back to /orders?name=order_name
For filter with note adding
  • /orders?name=order_name
  • /orders/edit/1
  • /orders/addNote/1
  • /orders/edit/1
  • and go back to /orders?name=order_name

I think the only way how to solve this is by Session. When user filters something on /orders?name=phil save it to session and then adding some salt as backlink to url.

Like/orders/edit/1?back=SALT

But then, I don't know how to have that salt in url persistent. As user can go to /orders/addNote/1?back=SALT with that SALT.

Part of this is solved by this article

biishmar's avatar

@DarkHarden if you know the flow of url cant you use the route name and redirect it in the end of every particular flow.

DarkHarden's avatar

@biishmar NO, as I said. You don't get it.

There could be many params in filter /orders?name=name&surname=surname&limit=50

And also - user can go on edit page from multiple pages...

biishmar's avatar

@DarkHarden Dont have to use SALT, just save it in session, in the controller check this session exists or not and append the param in session with the url and redirect.

DarkHarden's avatar

@biishmar Yes, I can use it in session as I said before, but there is another problem:

  • When I filter something like /orders?name=Alan&order_by=name
  • and then go to edit page /orders/edit/1
  • click on some other page like /payments
  • and then go to /orders - it redirects me to filter /orders?name=Alan&order_by=name and that is bad behavior...

That's why URL parameter will be much more helpfull.

Please or to participate in this conversation.