使用laravel分页增加行号

use*_*246 7 laravel laravel-3

如何使用laravel分页增加行号?当我使用分页时,我转到第2页及以上,它将回到开头.例如,我将分页(3)

    <thead>
    <tr>
       <th>No</th>
       <th>Name</th>
    </tr>
    </thead>
    <tbody>
    <?php $i = 1; ?>
    @foreach ($telephone->results as $telp)
    <tr>
       <td>
         {{$i++}}
       </td>
       <td>{{ $telp->name }}</td>                               
    </tr>
    @endforeach
    </tbody>
Run Code Online (Sandbox Code Playgroud)

当我转到第2页时,该号码将再次从1开始.

当我转到第2页时,我需要制作它,它将从4开始

o.v*_*o.v 10

在Laravel 5.3中,您可以使用firstItem():

@foreach ($items as $key => $value)    
  {{ $items->firstItem() + $key }}
@endforeach
Run Code Online (Sandbox Code Playgroud)


Jas*_*wis 6

您应该能够使用该getFrom方法获取当前页面结果的起始编号.因此,$i = 1;不应该设置你应该能够做到这一点.

<?php $i = $telephone->getFrom(); ?>
Run Code Online (Sandbox Code Playgroud)

在Laravel 3中没有getFrom方法,所以你需要手动计算它.

<?php $i = ($telephone->page - 1) * $telephone->per_page + 1; ?>
Run Code Online (Sandbox Code Playgroud)


Sod*_*pha 6

以下工作与laravel 5.4

<?php $i = ($telephone->currentpage()-1)* $telephone-
>perpage() + 1;?>
@foreach($telephone as $whatever)
<td> {{ $i++ }}</td>
@endforeach
Run Code Online (Sandbox Code Playgroud)


小智 5

Laravel 5.3

@foreach ($products as $key=>$val)
  {{ ($products->currentpage()-1) * $products->perpage() + $key + 1 }}
@endforeach
Run Code Online (Sandbox Code Playgroud)