I tried distinct before but somehow my query won't select the last comment. He always select the oldest comment. Then i tried it with groupBy instead of distinct. But this won't work either.
My current query:
\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();
It's pretty long. Hopfully someone can explain me why this won't work.