I've used laravel pagination to retrieve data from a table, I'm able to get the items of the first page but how to loop over each page and get the items from each page
Here is my code
public function handle()
{
$productsInstance = Products::query()->paginate(10);
$totalPages = $productsInstance->lastPage();
for ($i=1; $i <= $totalPages; $i++) {
foreach ($productsInstance as $productInstance) {
$items = $productInstance->items;
foreach ($items as $item) {
// operation performed on each item
}
}
}
}
The products table I'm querying and paginating is having a record of more than 200k, I'm able to perform the foreach operation on the first page but how to get items from each page