0
我有這樣的功能顯示:SortBy在Laravel
public function show($post)
{
$post = Post::whereId($post)->filter(\Request::only(['fields']))->firstOrFail();
return Response::json($post);
}
如何在這個函數添加sortBy(「一些領域從我送表」)?
方法。我必須包括什麼? – Georg
哦,沒有注意到'firstOrFail'。使用此方法將爲您提供一個Model實例而不是Collection,因此您必須使用SQL進行'order by'。讓我更新我的答案 – aaron0207
現在我得到這樣的結果,因爲沒有排序。 P.S.我編輯'desired_field'param我需要。 – Georg