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

Ok, I found solution using groupBy, of course now I can't use ->paginate, but I can make it manually, so it's not a big probelm.

return self::select('links.*')
            ->addSelect(DB::raw("COUNT(`likes`.`id`) AS `total_likes`"))
            ->join('likes', 'likes.link_id', '=', 'links.id')
            ->whereBetween('likes.created_at', array($start, $end))
            ->groupBy('likes.link_id')
            ->orderBy('total_likes', 'DESC')
            ->take($limit);
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

g1ntas g1ntas Joined 31 Aug 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.