2015-11-04 37 views
1

我正在使用laravel 4.2,由於某種原因,我需要訪問我認爲失敗的lastPage屬性。這是我的控制器分頁時的代碼。如何從結果集訪問受保護的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 
+0

如果我沒有錯,你實際上打算調用非保護方法' - > getLastPage()',它將返回'lastPage'的值。 *編輯*我沒有錯,你可以在[這裏的文檔]找到它(http://laravel.com/docs/4.2/pagination)。 Cntrl + f「getLastPage」 – Ohgodwhy

+0

@Ohgodwhy謝謝。太棒了。我的確使用'$ products-> getLastPage()'來訪問它。你能否在評論中回答它,以便我可以將其標記爲已接受的答案。 – KristCont

回答

1

對不起,我應該已經低於回答了這個問題。

您需要使用非保護方法->getLastPage()才能訪問受保護的方法。

您可以檢查documentation here

+0

非常有用。現在我不需要通過許多代碼來訪問它。謝謝 ! – KristCont