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

Shivamyadav's avatar

Get back to the laravel's previous url?

Is there any proper way to get back to the previous url url()->previous() works fine but when laravel validation fails it redirect to create or edit (same page) that is causing the issue to stuck into that loop of create or edit.

1 like
5 replies
Snapey's avatar

If you want to return to the route before they went to the create/edit, you need to stash the previous url in session or on the querystring so that after a successful submission you can use it to redirect to the original route.

1 like
Shivamyadav's avatar

I was looking something else , without modifying my business logic and other stuff just to modify the back-button component.

1 like
Shivamyadav's avatar

I was referring to the point that I do not want to change my business logic not even to use the query parameter for the previous url to work with that idea. I just want something which could not be like add the session and then get it (from session it also changes to the previous url ).

I want something to override the url()->previous() the way it works for the validation fails and stuck into the loop to avoid it.

Please or to participate in this conversation.