How to Prevent the Loop Incrementing Operator from Resetting Back to 1 in the Next Pagination Pages in Laravel
In this lesson, we will see how to prevent the loop incrementing operator from resetting back to 1 in the next pagination pages in Laravel, when working with Laravel and you loop through paginated data using foreach with the key and value the loop incrementing operator reset back to 1 in the next pagination pages so how can we solve this problem?
Solve the problem
To solve the problem use the code below:
@foreach ($posts as $key => $post) <tr> <td> {{($posts->perPage() * ($posts->currentPage() - 1)) + $key + 1}} </td> </tr>@endforeach