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

I have tried similar things but I never seem to be able do it without using DB:raw, if you find a way I would love to know.

    ->leftJoin(DB::raw("(SELECT COUNT(*) AS counter FROM favorites GROUP BY setting_id) favorites", "favorites.setting_id", "=", "")
    ->where("settings.state", "=", 1)
    ->orderBy("favorites.counter", "DESC");
Last updated 2 years ago.

Hi ! Are you sure your solution works because you don't return 'favorites.setting_id' from your leftJoin raw select so Eloquent can't perform the ON join clause.

Last updated 2 years ago.

Sign in to participate in this thread!


Your banner here too?


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.

© 2024 - All rights reserved.