*/ public function toArray(Request $request): array { $assignedEventsCount = $this->relationLoaded('assignedEvents') ? $this->assignedEvents->count() : $this->assignedEvents()->count(); return [ 'id' => $this->id, 'tenant_id' => $this->tenant_id, 'title' => $this->title, 'description' => $this->description, 'priority' => $this->priority, 'due_date' => $this->due_date?->toISOString(), 'is_completed' => (bool) $this->is_completed, 'collection_id' => $this->collection_id, 'assigned_events_count' => $assignedEventsCount, 'assigned_events' => $this->whenLoaded( 'assignedEvents', fn () => EventResource::collection($this->assignedEvents) ), 'created_at' => $this->created_at?->toISOString(), 'updated_at' => $this->updated_at?->toISOString(), ]; } }