Sometimes we need to fetch laravel pagination get last page or may be its laravel pagination first page url or even more laravel get pagination total. In this tutorial, I will show you how to get pagination last page, first page and total number of page in Laravel 9 application. 

If you do not know how to get pagination last page, first page and total number of page in Laravel 9 application, then this example is for you. Let's see the example of get total pages for pagination laravel:

Getting the first page from Laravel pagination:

<?php

$posts = Post::paginate(10)->onFirstPage();

 

Getting the last page from Laravel pagination:

<?php

$posts = Post::paginate(10)->lastPage();

 

Getting the total page from Laravel pagination:

<?php

$posts = Post::paginate(10)->total();

 

Read also: How To Change Default Pagination Limit In Laravel

 

Conclusion

Now we know laravel pagination get last page. Hope this laravel pagination first page url tutorial will help you to get laravel get pagination total.