*/ private Builder $query; public function execute(): self { $this->query = Membership::select('subactivities.slug', 'subactivities.name') ->selectRaw('COUNT(member_id) AS count') ->join('activities', 'memberships.activity_id', 'activities.id') ->join('subactivities', 'memberships.subactivity_id', 'subactivities.id') ->isAgeGroup() ->isMember() ->groupBy('subactivities.slug', 'subactivities.name') ->orderBy('subactivity_id'); return $this; } /** * @return array */ public function getResult(): array { return $this->query->get()->toArray(); } }