crowdLists() ->with(['crowdType', 'recipientCompany']) ->withCount('persons') ->get(); return CrowdListResource::collection($crowdLists); } public function store(StoreCrowdListRequest $request, Event $event): JsonResponse { Gate::authorize('create', [CrowdList::class, $event]); $crowdList = $this->crowdListService->create($event, $request->validated(), $request->user()); return $this->created(new CrowdListResource($crowdList->loadCount('persons'))); } public function update(UpdateCrowdListRequest $request, Event $event, CrowdList $crowdList): JsonResponse { Gate::authorize('update', [$crowdList, $event]); $crowdList = $this->crowdListService->update($crowdList, $request->validated(), $request->user()); return $this->success(new CrowdListResource($crowdList->loadCount('persons'))); } public function destroy(Event $event, CrowdList $crowdList): JsonResponse { Gate::authorize('delete', [$crowdList, $event]); $this->crowdListService->delete($crowdList, request()->user()); return response()->json(null, 204); } public function persons(Event $event, CrowdList $crowdList): AnonymousResourceCollection { Gate::authorize('viewPersons', [$crowdList, $event]); $persons = $crowdList->persons() ->with(['crowdType', 'company', 'pendingIdentityMatch.matchedUser']) ->paginate(50); return PersonResource::collection($persons); } public function addPerson(AddPersonToCrowdListRequest $request, Event $event, CrowdList $crowdList): JsonResponse { Gate::authorize('managePerson', [$crowdList, $event]); $festivalEventId = $event->parent_event_id ?? $event->id; $person = Person::where('event_id', $festivalEventId)->findOrFail($request->validated('person_id')); $this->crowdListService->addPerson($crowdList, $person, $request->user()); return $this->success(new CrowdListResource($crowdList->fresh()->loadCount('persons'))); } public function removePerson(Event $event, CrowdList $crowdList, Person $person): JsonResponse { Gate::authorize('managePerson', [$crowdList, $event]); $this->crowdListService->removePerson($crowdList, $person, request()->user()); return response()->json(null, 204); } }