Suppose I have 200 records in my DB. While displaying those records I want to paginate them. The normal approach would be doing something like
$tasks = Tasks::paginate(10);
Then
$tasks->links();
That code works fine. However, With that code you are going to run DB query every time you fetch those 10 rows (200/10= 20 times for all rows).
What I need is to fetch all data at once, store them in a collection (say $tasks
),Then paginate the resulting collection
instead of fetching again from DB.
Even more, I need to query something like "Get only 100 records and paginate them by 10 " which would be nice if it would be something like
Tasks::take(100)->paginate(10)
but unfortunately even that do not work.
Anyone with an idea on how to tackle these issues?