micky micky - 6 months ago 24
PHP Question

Using serial number iwith paginate

I am trying to retreive 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 controller:

$lists=telephone::orderBy('name')->simplePaginate(10);


so, until the first page the serial number is ok. but for the second page. i starts from 1 again.

Answer

Try setting $i to $lists->perPage() * ($lists->currentPage()-1)

$i = $lists->perPage() * ($lists->currentPage()-1);