Is there any way to get pagination pretty url or something like this in laravel 5.1?
I have 15 rows in per page. And I want to increment the row count number even on paginate.
<?php  $count = 1; ?>
<tr>     
    <th>No</th>
    <th>Year</th>
    <th>Action</th>
</tr>
@foreach($years as $year)
<tr>
    <td width="20%">{{ $count++ }}</td>
    <td width="50%">{{ $year->year }}</td>
    <td width="30%">
        <a href="{{ route('admin.year.edit', $year->id) }}" class="btn btn-info">Edit</a>
    </td>
</tr>
@endforeach
But when I goes to next page the $count var starts from beginning. How can I get $count = 16 and it will increment and so on?
In Laravel 5.3 you can now use the $loop variable in your views. So you could do something like:
{{ (($results->currentPage() - 1 ) * $results->perPage() ) + $loop->iteration }}
in your blade templates now.
You can use :
@foreach ($products as $key=>$val)
  {{ ($products->currentpage()-1) * $products->perpage() + $key + 1 }}
@endforeach
                        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