I want make a list with numbers

51 Views Asked by At

I want to make a list with numbers for example ( 1. lorem 2. ipsum 3 ...) I have pagination in the list. I'm trying to get an index from an array

    @foreach ($items as $index => $item)
       <li>$index + 1</li>
    @endforeach

This works, but when I use pagination, all pages start at 1 When using pagination, how can the numbering continue on the second page and not start over?

1

There are 1 best solutions below

1
Davit Zeynalyan On

You can use

@foreach ($items as $index => $item)
   <li>{{ ($items->currentPage() - 1) * $items->perPage() + $index + 1}} </li>
@endforeach

or you can it like this

@php
    $start = ($items->currentPage() - 1) * $items->perPage();
@endphp

@foreach ($items as $index => $item)
   <li>{{ $start + $index + 1}} </li>
@endforeach