Reputation: 477
I am using a system of infinite scroll pagination with Laravel and Ajax. It works like:
Book::orderBy('created_at')->paginate(5);
So, I am looking for something like:
$shown=10;
$showPerPage=5;
//The function that I am looking for
Book::orderBy('created_at')->paginateFrom(10,5)
This would load the five books after the number 10. I've seen Paginator::make()
, but I has two problems: first, it requires all the existing values, so I have to ask the db for every result, which is not very efficient, and second, I cannot pass an array to that funcion because Laravel return an object when you use ->get()
.
Any idea how could I do it?
Upvotes: 1
Views: 446
Reputation: 3695
I think this could solve:
$shown=10;
$showPerPage=5;
Book::orderBy('created_at')->skip($shown)->take($showPerPage)->get();
Basically the skip
method adds the OFFSET
clause and the take
adds the LIMIT
one.
Source: http://laravel.com/docs/queries
Upvotes: 1