我正在从Laravel 4升级到Laravel 5,并注意到我无法再在Paginator对象上调用getFrom()
或getTo()
。
我可以在源代码(Illuminate'Pagination'Pagintor.php
)中看到,与L4相比,它不再具有protected function calculateItemRanges()
。我在这里错过了什么吗?如何显示范围,例如 Now showing x of x
现在在拉拉维尔 5 中?这是我现在必须自己添加的东西吗?为什么首先要删除它?
其新方法称为firstItem()
和lastItem()
。
在源中:
/**
* Get the number of the first item in the slice.
*
* @return int
*/
public function firstItem()
{
return ($this->currentPage - 1) * $this->perPage + 1;
}
/**
* Get the number of the last item in the slice.
*
* @return int
*/
public function lastItem()
{
return $this->firstItem() + $this->count() - 1;
}
我会说,如果没有检索到数据,考虑到这些函数的当前逻辑,firstItem() 和 lastItem() 可能会有问题。
例如,控制器中的代码:
$users = App'User::select('id')->paginate(10);
$begin = $users->firstItem();
$end = $users->lastItem();
return view('users/index')->with('begin',$begin)->with('end',$end);
视图中的代码:
<p>showing item {{$begin}} to {{$end}}</p>
结果,它显示错误的信息:显示项目 1 到 0。
我已经创建了一个问题,并就此问题在 laravel/框架中提出了更改。