Sven B Sven B - 1 month ago 12
Ajax Question

Laravel ajax pagination set page

In my laravel project i use hashes in the url to keep track on selections of the user, so they are able to go back to a filter result. I dont want the page to refresh so I DONT UPDATE THE URL with Page=someid (except the hash) the response of the server looks like.

if ($request->ajax()) {
//The page I want to select posted with ajax
$paginaId = $request->input('page');
//some query like
$query = Table::Query();
//get 9 items
$rooms= $query->paginate(9);
//Return the response
return Response::json(View::make('front.rooms.render', array('rooms' => $rooms))->render());

The $paginaId represents the selected pagination page. Everything works fine except one part. I cant set the current page of the pagination. I viewed the documentation but couldn't find any solutions.


Try the following:

 $rooms = $query->paginate(9, ['*'], 'page', $paginaId);

In this case you can set $paginaId manualy