-1

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?

  • How many items are there per page? Or is that a variable? You need that information to be able to calculate the number. Also is it an ordered list `
      ` or unordered list `
      `?
    – Coola May 26 '23 at 16:55

1 Answers1

0

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
Davit Zeynalyan
  • 8,418
  • 5
  • 30
  • 55