From the docs...
By default, the current page is detected by the value of the page query string argument on the HTTP request.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have set up pagination for a large list of subscribers (over 7000); it working correctly. Each page shows a sub list of subscribers with an edit link for each. I am using a standard resource route; the edit button links to '/subscriber/<#id>/edit'
My question: Is there a way to detect which page the subscriber <#id> was on in the Subscriber::edit method? Paginate creates a url like:
/subscriber?page=3
My reason for doing this is that I want to save the page number and pass it on via hidden variable to the update method. Then I can redirect at the end of the update method to page the user back to the page he/she was on when they first hit the edit button. E.g. if subscriber being edited is on page 150, the user would be very frustrated when the system redirects back to /subscriber, which is page 1!
I suppose I could use a client side javascript to detect the page number on the uri and put it in a cookie or something like that. Doesn't seem very elegant solution!
**In summary: ** I want to be able to edit a user and when update is complete, redirect user back to the same page.
Final edit: My solution (below) was to set the client-side cookie and detect it and redirect. Not elegant, but simple and works.
Here is how I solved the problem. Not sure if it is elegant enough for Laravel, but I can't find another way.
In my index.blade.php display which displays all the subscribers, I added a client side cookie which saves the entire list of get variables on the URL.
<script>
document.cookie="pageurl=" + encodeURIComponent(window.location['search']);
</script>
Then when all updates are properly processed and saved in my update (and create method), I redirect thus:
return redirect('subscriber'.$_COOKIE['pageurl']);
I am aware that this does not use the Laravel cookie function, but since Laravel assumes that all cookies are encrypted, I see how you could possibly create a Laravel-compatible encrypted cookie on the client side.
I had originally thought to pass the information to the edit method and then on to the update method, but since all I need it for is the final redirect, I saved it locally as a cookie and then redirected the user to where he/she was at when he/she started the edit process. This preserves the page the user was on plus any search and/or sort parameters added.
I imagine there must be some safety issue here, but I am not aware of it.
Please or to participate in this conversation.