I have an array of results (more than 25 result) fetched from the database. I am trying to implement Laravel Pagination in my application.
What I want is paginate the results fetched.
What I get is pagination of the same results.
The code that I have used so far:
$result = array_slice($fetchAllProducts, 0, 12);
$paginateResults = new Illuminate\Pagination\LengthAwarePaginator($result, count($fetchAllProducts), 12);
I do get the pagination, but when working inspecting, on page 2, on page 3, and so on.. I get the result that is visible on page 1 of the pagination on all the subsequent pages of the pagination.
Kindly help me out with this. Any help is highly appreciated.
EDIT 1: The code
<?php
$productsInParent = $category->products;
$productsInParentCategory = new Illuminate\Support\Collection;
$allProducts = $allProductsFromChild = [];
foreach($productsInParent as $prodInParent) {
$allProducts[] = $prodInParent;
}
foreach($category->childs as $child) {
foreach($child->products as $productsInChildren) {
$allProductsFromChild[] = $productsInChildren;
}
}
$fetchAllProducts = array_merge($allProducts, $allProductsFromChild);
$result = array_slice($fetchAllProducts, 0, 12);
$paginateResults = new Illuminate\Pagination\LengthAwarePaginator($result, count($fetchAllProducts), 12);
?>
P.S.: I am trying to learn on my own how to integrate custom pagination in Laravel 5.1