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

mikola_systems's avatar

Return the user to the previous page

Hello! Need help. There is a list of records with pagination. URL: /admin/reviews

Post editing form is on a separate page: /admin/reviews/45/edit

When saving changes to the record, I would like to return the user to the previous page, given the page number of the page navigation on which the user was. Those. for example, if the user went to edit the post from the page admin/reviews?page=6 , return him to this page.

What I tried:

On the record list page, I saved the URL of the current page in session()->flash('back_url', url()->full()) , then in the post editing form I got the saved URL and redirected the user back. However, there is a problem here, if you move between pages in a list, then url()->full() already produces something like: /livewire/message/admin.table Sorry for the English, I'm writing through a translator.

0 likes
9 replies
mikola_systems's avatar

@tisuchi when we submit a livewire form, the redirect()->back() already refers to the page of the same form

mikola_systems's avatar

@tisuchi I go from the 2nd page of the list to edit the post, the URL::previous() contains: /admin/reviews?page=3 I submit the form and the url URL::previous() contains: /admin/reviews/15/edit

tisuchi's avatar

@shot_gamer

In your reviews list page, save the current page number as a variable, and then in your post editing form, retrieve the saved page number and use it to redirect the user back.

It's another concept.

1 like
mikola_systems's avatar

@tisuchi Understood. You just need to save the previous url to a variable in the form component in the mount() method and then use it when submitting the form. Thank you for your attention! Good for you!

1 like
vicodeveloper's avatar

Correct me if isn't work this, but.. I did next: maked public variable like public $previewUrl and then, in mount function I added $this->previewUrl = url()->previous(); and after, in myFunction I added $this->redirect($this->previewUrl);

Please or to participate in this conversation.