Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - Use $loop->iteration with pagination

Tags:

laravel

I'm trying to make something similar to reddit (just the ranking idea in a list of rows) and want each row counted consecutively.

Example Reddit listing

I can do this on one page with the tag

{{ $loop->iteration }}

Unfortunately, when I go to the second page, as I am using pagination, the numbers start over at 1. However, I would like them to continue from the last number on the previous page.

Any idea how to fix this?

I appreciate your help! :)

like image 528
Brad Ahrens Avatar asked Oct 23 '25 19:10

Brad Ahrens


1 Answers

you can use $loop->index instead of $loop->iteration in the following way

{{ ($players ->currentpage()-1) * $players ->perpage() + $loop->index + 1 }}
like image 81
Joyal Avatar answered Oct 26 '25 11:10

Joyal