The Issue
Consider the following layout:
Now imagine that each section within the above list, is retrieved by an entirely separate query on the database...
The content on the page is paginated as the user scrolls (lazy loading). Resultantly, each section is only visible once the previous section has been completely loaded like so:
For the purposes of the following example, please assume the following:
- Page size is 5
- Section 1 has 6 items
- Section 2 has 10 items
GET http://ift.tt/2bAiu6G
{
data: {
'section_1': [
// The first 5 items of section 1 are returned
]
},
laravel_pagination_stuff_etc...
}
GET http://ift.tt/2befCP4
{
data: {
'section_1': [
// The last item of section 1 is returned
],
'section_2': [
// The first 4 items of section 2 are returned
]
},
laravel_pagination_stuff_etc...
}
What I have tried
I have played around with Laravel Pagination like so:
// Determine which page to retrieve
$page = Input::get('page', 1);
$paginate = 5;
// Paginate the results
$offset = ($page * $paginate) - $paginate;
$items_for_current_page = array_slice($results, $offset, $paginate, true);
$results = new \Illuminate\Pagination\LengthAwarePaginator($items_for_current_page, count($results), $paginate, $page);
However, I am not familiar enough with the framework and library so before I spend hours/days going through the Laravel Pagination code, are there any Laravel pro's out there that can see a way to achieve the above in a simple way?
Additional Information
Just to be clear as to what I am asking; I am looking for a possible way to group and paginate two entirely separate queries into one page parameter. Is this possible?
Please note I am not asking, nor do I need, the code written for me. I am merely asking for a bit of guidance in the right direction in regards to the logic and the code.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire