Sven van den Boogaart
Sven van den Boogaart

Reputation: 12331

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.

Upvotes: 1

Views: 1890

Answers (1)

Iamzozo
Iamzozo

Reputation: 2358

Try the following:

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

In this case you can set $paginaId manualy

Upvotes: 7

Related Questions