Laravel 11 Pagination Add Query String Example
In this post, i will show you how to automatically append query string with pagination in laravel 11 application.
Laravel makes it easy to add pagination using the `paginate()` method on a model. To show the pagination links, you can use the `links()` method. This works well for basic pagination.
However, if your page has filters (like showing only active users), you need to include the filter data in the pagination links. For example, to keep the pagination for only active users, you can add the "is_active" filter to the query string using the `appends()` method.
we will use appends() function to add automatically add query string to pagination url.
Let's see the example:
Query String URL:
http://localhost:8000/posts?is_active=1&page=1
Example:
we will use appends() method with request()->query() method to pass query string.
{{ $posts->appends(request()->query())->links('pagination::bootstrap-5') }}
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Use Quill Rich Text Editor in Laravel 11?
- Laravel 11 Breeze Multi Auth Tutorial
- Laravel 11 Reverb Real-Time Notifications Example
- Laravel 11 Send Email with Attachment Example
- How to Add Text to Image in Laravel 11?
- How to Generate Thumbnail Image in Laravel 11?
- Laravel 11 Add or Remove Multiple Input Fields with jQuery Example
- How to Add Blur Effect to Image in Laravel 11?
- Laravel 11 Real-Time Notifications using Echo Socket.IO and Redis
- How to Compress Image Size in Laravel 11?
- Laravel 11 MongoDB CRUD Application Tutorial
- Laravel 11 RouteServiceProvider Configuration Example
- Laravel 11 Socialite Login with Gitlab Account Example
- Laravel 11 Socialite Login with Github Account Example
- Laravel 11 CKeditor Image Upload Example