【发布时间】:2015-11-04 12:50:16
【问题描述】:
我正在使用 laravel 4.2,出于某种原因,我需要访问我认为失败的 lastPage 属性。这是我的控制器在分页时的代码。
$products = Product::where('status', '=', 'available')->paginate(20);
下面是我的视图文件中var_dump($products) 的一部分,我需要知道如何正确访问它。
protected 'total' => int 10491
protected 'hasMore' => null
protected 'perPage' => int 20
protected 'currentPage' => int 1
protected 'lastPage' => int 525
protected 'from' => int 1
protected 'to' => int 20
【问题讨论】:
-
如果我没记错的话,您实际上是在调用不受保护的方法
->getLastPage(),它将返回lastPage的值。 edit我没看错,你可以在the documentation here找到。 Cntrl +f "getLastPage" -
@Ohgodwhy 谢谢。这太棒了。我确实使用“$products->getLastPage()”访问它。能否请您不要在评论中回答,以便我可以将其标记为已接受的答案。
标签: php laravel laravel-4 pagination