如何从结果集中访问受保护的lastPage属性


How to access protected lastPage property from result set

我正在使用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()来访问该受保护方法。

您可以在此处查看文档。