[英]Laravel Where clause, paginate and sortByDesc
我正在做一個項目,我想使用 where 子句,分頁,然后按特定順序對集合進行排序。 我已經嘗試了下面的結果,但不斷拋出以下方法的錯誤:
Illuminate\\Database\\Eloquent\\Collection::links 不存在。 (查看:/Applications/XAMPP/xamppfiles/htdocs/vermex/resources/views/equipments.blade.php)
Product 模型是我獲取數據並將其存儲在名為$equipment
的變量中的地方。 如果有更好的方法來做到這一點,請幫助。
public function equipments()
{
$equipments = Product::where('product_category_id', 3)->paginate(2)-
>sortByDesc('id');
return view('equipments', compact('equipments'));
}
嘗試將orderBy
放在paginate
之前
$equipments = Product::where('product_category_id', 3)->orderBy('id', 'desc')->paginate(2);
sortByDesc
是一種收集方法。
paginate
將需要最后才能在刀片視圖中提供鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.