$this->id, 'festival_section_id' => $this->festival_section_id, 'time_slot_id' => $this->time_slot_id, 'location_id' => $this->location_id, 'title' => $this->title, 'description' => $this->description, 'instructions' => $this->instructions, 'coordinator_notes' => $this->when( $this->shouldShowCoordinatorNotes($request), $this->coordinator_notes, ), 'slots_total' => $this->slots_total, 'slots_open_for_claiming' => $this->slots_open_for_claiming, 'is_lead_role' => $this->is_lead_role, 'report_time' => $this->report_time, 'actual_start_time' => $this->actual_start_time, 'actual_end_time' => $this->actual_end_time, 'allow_overlap' => $this->allow_overlap, 'status' => $this->status, 'filled_slots' => $this->filled_slots, 'fill_rate' => $this->fill_rate, 'effective_start_time' => $this->effective_start_time, 'effective_end_time' => $this->effective_end_time, 'created_at' => $this->created_at->toIso8601String(), 'time_slot' => new TimeSlotResource($this->whenLoaded('timeSlot')), 'location' => new LocationResource($this->whenLoaded('location')), 'festival_section' => new FestivalSectionResource($this->whenLoaded('festivalSection')), ]; } private function shouldShowCoordinatorNotes(Request $request): bool { $user = $request->user(); if (! $user) { return false; } if ($user->hasRole('super_admin')) { return true; } $shift = $this->resource; $event = $shift->festivalSection?->event; if (! $event) { return false; } return $event->organisation->users() ->where('user_id', $user->id) ->wherePivot('role', 'org_admin') ->exists() || $event->users() ->where('user_id', $user->id) ->wherePivot('role', 'event_manager') ->exists(); } }