Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

morilog morilog Joined 12 Mar 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.