*/ public function getMostPlayed(int $count = 6, ?User $user = null): Collection { $user ??= auth()->user(); return Artist::query() ->leftJoin('songs', 'artists.id', '=', 'songs.artist_id') ->leftJoin('interactions', static function (JoinClause $join) use ($user): void { $join->on('interactions.song_id', '=', 'songs.id')->where('interactions.user_id', $user->id); }) ->groupBy([ 'artists.id', 'play_count', 'artists.name', 'artists.image', 'artists.created_at', 'artists.updated_at', ]) ->isStandard() ->orderByDesc('play_count') ->limit($count) ->get('artists.*'); } public function getOne(int $id): Artist { return Artist::query()->find($id); } /** @return Collection|array */ public function getByIds(array $ids): Collection { return Artist::query() ->isStandard() ->whereIn('id', $ids) ->get(); } public function paginate(): Paginator { return Artist::query() ->isStandard() ->orderBy('name') ->simplePaginate(21); } }