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

ToxifiedM's avatar

Want to clean up the url query params on certain conditions - Laravel Inertia Vue

Currently I am fetching and paginating the data and it is all seamless, works great, but I need to set a certain condition, one of such condition is when the user is on 1st page or when he has paginated back to the first page, I need to clear the parameter at that point i.e. from http://127.0.0.1:8000/users?page=1 to http://127.0.0.1:8000/users.

Something like Caleb has been using in withPagination trait, in Livewire.

    public $page = 1;

    public function getQueryString()
    {
        return array_merge(['page' => ['except' => 1]], $this->queryString);
    }

How that can be attained with my current approach? Please throw some light on here. Thanks already!

0 likes
2 replies
marosmjartan's avatar
if ($page == 1){
	return redirect()->to(url()->current());  // url()->current() returns base URL without query
}
ToxifiedM's avatar

Where should I define the above it as I am paginating from the frontend?

Please or to participate in this conversation.