megacolorboy

Back

Published on September 28th, 2020

Laravel

Get pagination data by page number

By default, Laravel's paginator checks the value of the page based on the query string and uses that to display the results and also, it generates links to previous and next pages as well.The method takes the following parameters by default:So, if you want to fetch the pagination data of a specific page, then just write this:Hope you found this article useful!

1 minute read

By default, Laravel's paginator checks the value of the page based on the query string and uses that to display the results and also, it generates links to previous and next pages as well.

The paginate() method takes the following parameters by default:


public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null);

So, if you want to fetch the pagination data of a specific page, then just write this:


$pageNumber = 5;
$data = ExampleModel::paginate(5, ['*'], 'page', $pageNumber);

Hope you found this article useful!