increment row number with laravel pagination

user2194246 picture user2194246 · Aug 2, 2013 · Viewed 16.3k times · Source

How to make increment row number with laravel pagination ? When i use pagination and i go to page 2 and above it will back to beginning. for example i will paginate(3)

    <thead>
    <tr>
       <th>No</th>
       <th>Name</th>
    </tr>
    </thead>
    <tbody>
    <?php $i = 1; ?>
    @foreach ($telephone->results as $telp)
    <tr>
       <td>
         {{$i++}}
       </td>
       <td>{{ $telp->name }}</td>                               
    </tr>
    @endforeach
    </tbody>

when i go to page 2 the number will start from 1 again.

i need to make it when i go to page 2 it will start from 4

Answer

o.v picture o.v · Dec 7, 2016

In Laravel 5.3 you can use firstItem():

@foreach ($items as $key => $value)    
  {{ $items->firstItem() + $key }}
@endforeach