Support the ongoing development of →
Database Eloquent
Last updated 7 months ago.

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.

Last updated 7 months ago.

I can't test it, but it should be something along these lines.

$results = DB::table('tags') ->join('post_tag', '', '=', 'post_tag.tag_id') ->select(DB::raw(',, 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.

Last updated 7 months ago.

Sign in to participate in this thread!


Your banner here too?

morilog morilog Joined 12 Mar 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 - All rights reserved.