persons()->with('crowdType'); if ($request->filled('crowd_type_id')) { $query->where('crowd_type_id', $request->input('crowd_type_id')); } if ($request->filled('status')) { $query->where('status', $request->input('status')); } return new PersonCollection($query->get()); } public function show(Event $event, Person $person): JsonResponse { Gate::authorize('view', [$person, $event]); $person->load(['crowdType', 'company']); return $this->success(new PersonResource($person)); } public function store(StorePersonRequest $request, Event $event): JsonResponse { Gate::authorize('create', [Person::class, $event]); $person = $event->persons()->create($request->validated()); return $this->created(new PersonResource($person->fresh()->load('crowdType'))); } public function update(UpdatePersonRequest $request, Event $event, Person $person): JsonResponse { Gate::authorize('update', [$person, $event]); $person->update($request->validated()); $person->load(['crowdType', 'company']); return $this->success(new PersonResource($person->fresh()->load(['crowdType', 'company']))); } public function destroy(Event $event, Person $person): JsonResponse { Gate::authorize('delete', [$person, $event]); $person->delete(); return response()->json(null, 204); } public function approve(Event $event, Person $person): JsonResponse { Gate::authorize('approve', [$person, $event]); $person->update(['status' => 'approved']); return $this->success(new PersonResource($person->fresh()->load('crowdType'))); } }