If you know the longhand query, why? Eloquent has to convert it right back to this at execution time.
Sorry not an answer, just curious.
I can't test it, but it should be something along these lines.
$results = DB::table('tags') ->join('post_tag', 'tags.id', '=', 'post_tag.tag_id') ->select(DB::raw('tags.id, tags.name, tags.slug, count(post_tag.tag_id) AS tagsCount')) ->groupBy('post_tag.tag_id') ->take(10) ->get();
Edit: I believe you need to use DB::raw in the select statement to use the "AS" to define the field name.
Sign in to participate in this thread!
We'd like to thank these amazing companies for supporting us