我嘗試不同之前,但不知何故,我的查詢將不會選擇最後一條評論。他總是選擇最古老的評論。然後我用groupBy而不是獨特的方式嘗試過。但是這也行不通。Laravel查詢不想選擇最後一個
我當前的查詢:
\App\Comment::limit(5)->groupBy('comments.id')
->orderBy('comments.id', 'desc')
->join('topics', 'comments.topic_id', '=', 'comments.id')
->select('comments.user_id', 'topics.id', 'topics.name')
->whereIn('topics.cat_id', $cats)
->where([['comments.removed', '=', false],['topics.removed', '=', false]])
->get();
這是相當長的。 有人可以解釋爲什麼這不起作用。
什麼你想達到什麼目的? – avonnadozie
@avonnadozie抱歉,不好解釋我想根據最後的評論選擇5個主題。 – Smokegun
無需等待我想選擇主題未刪除且處於所選類別中的最後評論 – Smokegun