我真的在雄辩上混淆了在差异表中存在流行参数时用于选择流行线程的雄辩,所以我的表看起来像Bellow:
-------------------
| thread |
-------------------
|id (int) |
|title (varchar) |
|value (text) |
|timestamp |
-------------------
-------------------
| comment |
-------------------
|id (int) |
|value (text) |
|id_thread (id) |
|timestamp |
-------------------
因此,在上表中,我想使用雄辩的拉拉维尔(Laravel)通过大多数评论的线程显示所有线程。在这种情况下,我花了很多时间,但是没有付清。
尝试
$tops = Thread::join('comments', 'comments.id_thread', '=', 'threads.id')
->select(
'thread.*',
DB::raw('count(comments.id) as total_comments')
)->orderBy('total_comments', 'desc')
->groupBy('threads.id') // or 'id'
->take(10) //top 10 ?
->get();
您可能会遇到与Groupby有关的错误,说" ...因为它不包含在Grouby中"。这意味着您必须对该列进行分组。显示该错误的每个列,将其添加到组中。