Laravel 5.1分页计数 [英] Laravel 5.1 pagination count
问题描述
我正在使用Laravel的分页器来显示每页100个结果.当前,在每一行的前面,我正在显示数据库字段的ID.但是,我想显示计数.
I am using the paginator of Laravel to display 100 results per page. In the front of each row I'm currently displaying the ID of the database field. However, I want to display the count.
我在stackoverflow上发现了一些解决Laravel 4问题的线程
在他们所说的地方,您应该这样解决
Where they say, you should solve it like this
<?php $count = $players->getFrom(); ?>
@foreach ($players as $player)
<tr>
<td>{{ $count++ }}. </td>
</tr>
@endforeach
或类似的
<?php $count = $players->getFrom() + 1; ?>
@foreach ($players as $player)
...
这里的问题是Laravel 5.1不再具有getForm
方法. 升级指南说,我已将getFrom
替换为firstItem
.不幸的是,我没有得到正确的数字.
The problem here, is that Laravel 5.1 doesn't have the getForm
method anymore. The upgrade guide says to replace getFrom
by firstItem
, which I did. Unfortunetely, I'm not getting the correct numbers.
我这样尝试过
<?php $count = $pages->firstItem() + 1 ?>
@foreach ($pages as $page)
@include('pages.singlepagebasic')
@endforeach
像这样
{{ $count = $pages->firstItem() }}
@foreach ($pages as $page)
@include('pages.singlepagebasic')
@endforeach
//pages.singlebasic.blade.php
//pages.singlebasic.blade.php
{{ $count ++ }}
但是我的网站始终只显示数字"2",而不是递增计数.我该如何实现?
but my site always displays only the number "2" instead of counting up. How do I achieve that?
推荐答案
只需使用它来获取页数
$players->lastPage()
或以此获取项目计数
$players->total()
如果您希望每个条目都计数DONT DO {{$ count ++}},因为它回显数据.而是那样做
If you want every entry count DONT DO {{ $count++ }} because its echoing data. Instead do like that
<?php $count++; ?>
{{ $count }}
这篇关于Laravel 5.1分页计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!