*/ abstract protected function getQuery(): Builder; /** * @param class-string $type * * @return Collection */ public function getPages(string $type): Collection { return $this->get($type)->groupBy( fn ($member) => Str::slug( "{$member->lastname}{$member->address}{$member->zip}{$member->location}", ), )->map(fn ($page) => new Page($page)); } /** * @param class-string $type * * @return EloquentCollection */ private function get(string $type): EloquentCollection { return $this->getQuery() ->with([ 'payments' => fn ($query) => $type::paymentsQuery($query) ->orderByRaw('nr, member_id'), ]) ->get() ->filter(fn (Member $member) => $member->payments->count() > 0); } }