validated('event_id')); if ($event->isSubEvent()) { $event = $event->parent; } $person = Person::where('user_id', $request->user()->id) ->where('event_id', $event->id) ->with([ 'crowdType', 'shiftAssignments.shift.festivalSection', 'shiftAssignments.shift.timeSlot', 'volunteerAvailabilities.timeSlot', 'fieldValues.registrationFormField', 'sectionPreferences.festivalSection', ]) ->first(); if (! $person) { return $this->notFound('No registration found for this event'); } $upcomingShift = $person->shiftAssignments() ->where('status', ShiftAssignmentStatus::APPROVED) ->whereHas('shift.timeSlot', fn ($q) => $q->where('date', '>=', now()->toDateString())) ->with([ 'shift:id,title,festival_section_id,time_slot_id,location_id', 'shift.timeSlot:id,name,date,start_time,end_time', 'shift.festivalSection:id,name', 'shift.location:id,name', ]) ->orderBy( TimeSlot::select('date') ->whereColumn('time_slots.id', 'shift_assignments.time_slot_id') ->limit(1) ) ->orderBy( TimeSlot::select('start_time') ->whereColumn('time_slots.id', 'shift_assignments.time_slot_id') ->limit(1) ) ->first(); $formattedShift = null; if ($upcomingShift) { $timeSlot = $upcomingShift->shift->timeSlot; $formattedShift = [ 'date' => $timeSlot->date->toDateString(), 'time' => substr($timeSlot->start_time, 0, 5) . ' - ' . substr($timeSlot->end_time, 0, 5), 'title' => $upcomingShift->shift->title, 'section' => $upcomingShift->shift->festivalSection?->name, 'location' => $upcomingShift->shift->location?->name, ]; } $data = (new PersonResource($person))->resolve(); $data['upcoming_shift'] = $formattedShift; return $this->success($data); } }