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);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community