*/ protected function getQuery(Form $form, ParticipantFilterScope $filter): HasMany { return $form->participants()->withFilter($filter)->withCount('children')->with('form'); } /** * @return LengthAwarePaginator */ public function handle(Form $form, ParticipantFilterScope $filter): LengthAwarePaginator { return $this->getQuery($form, $filter)->paginate(15); } public function asController(Form $form, ?int $parent = null): AnonymousResourceCollection { $filter = ParticipantFilterScope::fromRequest(request()->input('filter')); $data = match ($parent) { null => $this->handle($form, $filter), -1 => $this->getQuery($form, $filter)->where('parent_id', null)->paginate(15), default => $this->getQuery($form, $filter)->where('parent_id', $parent)->get(), }; return ParticipantResource::collection($data)->additional(['meta' => ParticipantResource::meta($form)]); } }