I am trying to retrieve serial number in the blade template with variable i:
<?php $i=0;?>
@foreach ($lists as $li)
<tr><td><?php $i++;?>{{$i}}</td><td>{{$li->Name}}</td><td>{{$li->Telephone}}
</td><td>{{$li->mobile}}</td>
@endforeach
{!! $lists->render() !!}
but I am using paginate in the controller:
$lists=telephone::orderBy('name')->simplePaginate(10);
So, the first page's serial number is ok. But for the second page i starts from 1 again.
You can also use
@foreach($lists as $index => $list)
{{$index + $lists->firstItem()}} //S.N
@endforeach
$index is the row number in that result set and $lists->firstItem() will get the result number of the first item in the paginated results.
UPDATE:
The solution below starts from 0 instead of 1 for the first page. To start from 1:
$i = ($lists->perPage() * ($lists->currentPage() - 1)) + 1;
Try setting $i to $lists->perPage() * ($lists->currentPage() - 1)
$i = $lists->perPage() * ($lists->currentPage() - 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With