Add pagination count * (page - 1) to the key
Feb 1, 2020
3
Level 3
Customize Index for records with pagination in foreach loop.
I need to have an indexing / sr.no on the record been displayed in foreach loop.
21 | xyz | ok | success
22 | abc | ok | success
23 | axyz | ok| error
24 | xabc | ok | success
Now, normally I would use the id. but in this case, I don't want to show id's. If i use the $key from foreach loop, for the first page it works well. but when I go to next page, the count gets started again like 1,2,3,4,5,6,7 which should have been 21,22,23,24,25,26,27 if the pagination limit was 20 per page.
what is a proper solution for this situation?
Level 3
Pretty Close the answer was. below is the code:
{{ ( $users->perPage() * ($users->currentPage() - 1)) + $key + 1}}
you missed to add + 1 to the equation as array starts from zero.
Please or to participate in this conversation.