Handle Query String Pagination With WithQueryString Helper In Laravel

Hello Artisan,

In this quick Laravel tutorial, I will show you that how we can handle pagination with a query string. You know that after searching or filtering data with pagination, we need to handle pagination along with the requested query string. Laravel provides us predefined function call withQueryString and you may use this method to append all of the current request's query string values to the pagination links.

Suppose we have a link query string like www.example.com?page=1&q=query&status=active&country=bd and we need to handle pagination in every request with pagination. Then we can use this withQueryString method in this case.

So no need to do anything more to handle pagination with a query string. So let's see the example query:

$users = User::paginate(15)->withQueryString();

 

Read also: How to Override Default Pagination Number in Laravel

 

Hope this tutorial will help you to handle your pagination with the query string in Laravel.

 

#laravel #laravel-8x