Laravel 8 Pagination Example

In this article, we will see laravel 8 pagination example. As we know laravel provide many paginate method for custom pagination in laravel 8, Here, we will see information about the laravel paginate() function and how to use pagination in laravel 8 with example.

So, let's see pagination example in laravel 8, custom pagination in laravel 8, how to use pagination in laravel 8, laravel 8 pagination bootstrap, laravel 8 pagination, paginate laravel 8, laravel paginate collection, laravel pagination example blade, pagination in laravel 7/8/9.

Using this method you can simply customize your pagination in laravel 8, below paginator instance provides additional pagination information.


Using this function you can get the number of items on the current page.

"count:7" // no of count




This function is used for the total number of matching items in the data store. It is not available when we use the simplePaginate() function in laravel.



It will help you to set the query string variable used to store the page.

Illuminate\Pagination\Paginator {#1290 ▼
  #hasMore: true
  #items: Illuminate\Database\Eloquent\Collection {#1288 ▶}
  #perPage: 7
  #currentPage: 1
  #path: "http://localhost:8000"
  #query: []
  #fragment: null
  #pageName: "page"
  +onEachSide: 3
  #options: array:2 [▼
    "path" => "http://localhost:8000"
    "pageName" => "page"



This function gets the query string variable used to store the page. And also get the page that is set by using the setPageName() function.




Using this method we can get the resulting number of the first item in the results.

1 //get first item



It will help you to check if there are more items in the data store. In this function, you will get a true or false value. if you have more pages then it will return true otherwise get a false value.

true // get boolean value



$paginator->getUrlRange($start, $end)

This method create a range of pagination URLs.

array:5 [▼
  1 => "http://localhost:8000?page=1"
  2 => "http://localhost:8000?page=2"
  3 => "http://localhost:8000?page=3"
  4 => "http://localhost:8000?page=4"
  5 => "http://localhost:8000?page=5"



You can get the current page number. In this function, you will get current page values like 1,2, etc.  

2 // get current page value 



You can check if there are enough items to split into multiple pages.

true // get boolean value



Get the resulting number of the last item in the results. In your data getting last no record using this function.

7 // get last record




Get the paginator options.

array:2 [▼
  "path" => "http://localhost:8000"
  "pageName" => "page"



Get the items for the current page. items() function return details of your current page like the total no of records on the current page with its details in the array.

array:7 [▼
  0 => App\Models\Post {#1300 ▼
    #table: "posts"
    #guarded: []
    #connection: "mysql"
    #primaryKey: "id"
    #keyType: "int"
    +incrementing: true
    #with: []
    #withCount: []
    #perPage: 15
    +exists: true
    +wasRecentlyCreated: false
    #attributes: array:14 [▶]
    #original: array:14 [▶]
    #changes: []
    #casts: []
    #classCastCache: []
    #dates: []
    #dateFormat: null
    #appends: []
    #dispatchesEvents: []
    #observables: []
    #relations: []
    #touches: []
    +timestamps: true
    #hidden: []
    #visible: []
    #fillable: []
  1 => App\Models\Post {#1301 ▶}
  2 => App\Models\Post {#1302 ▶}
  3 => App\Models\Post {#1303 ▶}
  4 => App\Models\Post {#1304 ▶}
  5 => App\Models\Post {#1305 ▶}
  6 => App\Models\Post {#1306 ▶}



 Using this method you can get the URL for the next page.





Get the URL for the previous page. if the current page is 1 then the previous URL gets a null value.




The number of items to be shown per page.

7 // total no of record in per page



Get the page number of the last available page. (Not available when using simplePaginate).



Determine if the paginator is on the first page.

false // return boolean value




Get the URL for a given page number.



You might also like :


Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.