I am using a system of infinite scroll pagination with Laravel and Ajax. It works like:
- I load the first 10 results, simply using
Book::orderBy('created_at')->paginate(5);
- Then, via Ajax I call to another function which must return the next 5 values. But I don't want the first 5 values, only the 5 new ones.
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?