Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel get specific page programmatically

I am trying to implement pagination with Laravel and jQuery ajax.

I need to send page number to a post controller and get the results for that specific page.

So my question is. Is there a way to get a specific page from the Paginator in Laravel, something like $model->page(3) for getting the third page from the paginated data as an array, so i can serialize it as JSON and send back as a response?

UPDATE:

Thanks to the good people on Laravel's irc channel I found the answer. So i will write here as help for others. The magic is this:

Input::merge(array("page" => $page_number))

you actually make Laravel's Paginator thinks that a "page" parameter is passed in the action. Neat huh :)

like image 506
djandreski Avatar asked Nov 16 '25 11:11

djandreski


1 Answers

Thanks to the good people on Laravel's irc channel I found the answer. So i will write here as help for others. The magic is this:

Input::merge(array("page" => $page_number))

you actually make Laravel's Paginator thinks that a "page" parameter is passed in the action. Neat huh :)

like image 106
djandreski Avatar answered Nov 18 '25 04:11

djandreski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!