I have set a pagination in my specific view/site, and it works.
The problem is I have a php counter:
<?php $count = 0;?>
@foreach ($players as $player)
<?php $count++;?>
<tr>
<td>{{ $count }}. </td>
and whenever I switch pages, it starts from 1.
How could I change that?
In order to achieve that, you need to initialize the value of counter:
<?php $count = (($current_page_number - 1) * $items_per_page) + 1; ?>
Notice I'm first subtracting 1
from current page, so the first page number is 0
. Then I'm adding 1
to the total result, so your first item starts with 1
, instead of 0
.
Laravel Paginator provides a handy shortcut for that:
<?php $count = $players->getFrom() + 1; ?>
@foreach ($players as $player)
...
There are a few others that you can use as you like:
$players->getCurrentPage();
$players->getLastPage();
$players->getPerPage();
$players->getTotal();
$players->getFrom();
$players->getTo();
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