Ad

Get Pagination Data By A Specific Page Number

- 1 answer

I want to get Data by page number, in normal when we use this code

$jobs = Jobs::paginate(10);

laravel get data by GET "page" parameter that defined in URL, if our URL be http://www.example.com/job?page=2 laravel return data of page 2
I want to do this without using the page parameter in URL

I want you to introduce me something like this

$jobs = Jobs::paginate(10,[
'page'=>2
]);
Ad

Answer

Laravel paginator automatically checks for the the value of page in query string and uses it to paginate the results. The result also automatically generates the next and previous links to help you add them directly

The default paginate method takes the following parameters.

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

so you use like this

$jobs = Jobs::paginate(5, ['*'], 'page', $pageNumber);

The default convention is

example.com/job?page=2 
example.com/job?page=3

Also if you use $jobs->links() to generate the navigation button

Ad
source: stackoverflow.com
Ad