Laravel

Get pagination data by page number

Published on September 28th, 2020


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!