How to Add Query String Automatically on Laravel Pagination Links?

By Hardik Savani April 16, 2024 Category : Laravel

Hey Artisan,

Are you looking for an example of laravel append query string to pagination. I explained simply step by step laravel add query string to pagination url. you will learn laravel pagination add query string all input. you can understand a concept of laravel query string pagination example.

You can use this example with laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 example.

we will use withQueryString() function to add automatically add query string to pagination url.

withQueryString() is a method in Laravel that returns a new instance of the current request with the current query string. It is commonly used when you want to include the current query string parameters in a URL that you are generating.

Query String URL:

But where is problem. when you search any for example "tes" and get the result but when you click on next page you can't filter on name as you did "tes". so at that time we have to appends that query string on pagination links. so, let's see how to solve this issue.

View Example:

{{ $posts->withQueryString()->links() }}

I hope it can help you.

Tags :