3
votes

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 :)

2
you really should post your update as an answer to the question. This will help the community, as it's will mark you question as answered.AndHeiberg

2 Answers

3
votes

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 :)

0
votes

To follow up, you need to start your route to get. Like: Route::get('...');

If Route with post, like Route::post('...'); this not working.

djandreski thank you so much for this solution, I hope it will help others.