timeSlots()->orderBy('date')->orderBy('start_time')->get(); if ($event->isSubEvent() && request()->boolean('include_parent') && $event->parent_event_id) { $parentTimeSlots = TimeSlot::where('event_id', $event->parent_event_id) ->with('event') ->orderBy('date') ->orderBy('start_time') ->get(); $timeSlots->load('event'); $timeSlots->each(fn (TimeSlot $ts) => $ts->setAttribute('source', 'sub_event')); $parentTimeSlots->each(fn (TimeSlot $ts) => $ts->setAttribute('source', 'festival')); $timeSlots = $timeSlots->merge($parentTimeSlots) ->sortBy([['date', 'asc'], ['start_time', 'asc']]) ->values(); } return TimeSlotResource::collection($timeSlots); } public function store(StoreTimeSlotRequest $request, Event $event): JsonResponse { Gate::authorize('create', [TimeSlot::class, $event]); $timeSlot = $event->timeSlots()->create($request->validated()); return $this->created(new TimeSlotResource($timeSlot)); } public function update(UpdateTimeSlotRequest $request, Event $event, TimeSlot $timeSlot): JsonResponse { Gate::authorize('update', [$timeSlot, $event]); $timeSlot->update($request->validated()); return $this->success(new TimeSlotResource($timeSlot->fresh())); } public function destroy(Event $event, TimeSlot $timeSlot): JsonResponse { Gate::authorize('delete', [$timeSlot, $event]); $timeSlot->delete(); return response()->json(null, 204); } }