I have 2 tables and in first comments and article id, in second article title, id , category of article. I want has a title of article which has the most comments.
SELECT comments.article_id, news.title, news.category_id,
COUNT(comments.id) as counts
FROM comments
JOIN news ON news.id = comments.article_id
GROUP BY(article_id)
ORDER BY counts DESC
LIMIT 3
I tried this:
$articles = DB::table('comments')
->join('news', 'news.id', '=', ' comments.article_id')
->select(comments.article_id', 'news.title', ' news.category_id')
->count('comments.id')
->groupBy('article_id')
->orderBy(DB::raw('count(comments.id)', 'desc')
->limit(3)
->get();
But had:
Call to a member function groupBy() on integer