Serial no in foreach loop with pagination

We can use foreach collection items index as serial no (SL) in pagination.

1...
2<th>Serial</th>
3 ...
4 @foreach ($products as $product)
5 <tr>
6 <td>{{ $loop->index + $product->firstItem() }}</td>
7 ...
8 @endforeach

it will solve the issue of next pages(?page=2&...) index count from continue.

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord