How to add automatically query string to Laravel pagination links

How to add automatically query string to Laravel pagination links

In this post we will give you information about How to add automatically query string to Laravel pagination links. Hear we will give you detail about How to add automatically query string to Laravel pagination linksAnd how to use it also give you demo for it if it is necessary.

In this tutorial, i will tell you how to add automatically query string to Laravel pagination links and when you need it ?

Sometime you filter records in Laravel and try to paginate to next page then additional query string is lost with pagination and results are reset to default without filter option. In this scenario, you can add all query sting by single command in Laravel with appends method.

Let’s have a look on given example.

  1. $products->appends(request()->all())->render();
  2. or
  3. $products->appends(Input::all())->render();
$products->appends(request()->all())->render();or$products->appends(Input::all())->render();

You can manually add query string to Laravel pagination links.

  1. $products->appends(['sort'=>'name'])->render()
$products->appends(['sort' => 'name'])->render()

You can also customize your pagination link url by using setPath methods.

  1. $products= AppProduct::paginate(10);
  2. $products->setPath('custom/url');
 $products = AppProduct::paginate(10); $products->setPath('custom/url');

Hope this code and post will helped you for implement How to add automatically query string to Laravel pagination links. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  73  =  82

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US