【问题标题】:How to access protected lastPage property from result set如何从结果集中访问受保护的 lastPage 属性
【发布时间】: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


【解决方案1】:

对不起,我应该在下面回答。

您需要使用不受保护的方法->getLastPage() 来访问该受保护的方法。

您可以查看documentation here

【讨论】:

  • 非常有用。现在我不必通过很多行代码来访问它。谢谢!
猜你喜欢
  • 1970-01-01
  • 2015-05-21
  • 2017-10-29
  • 2012-09-27
  • 1970-01-01
  • 2014-11-06
  • 2012-12-28
  • 2014-09-13
  • 1970-01-01
相关资源
最近更新 更多