*/ public function toArray(Request $request): array { return [ 'id' => $this->id, 'note' => $this->note, 'priority' => $this->priority, 'image' => $this->image, 'code' => $this->code, 'modality' => $this->modality, 'status' => $this->status instanceof DocumentStatusEnum ? $this->status->name : $this->status, 'priority' => $this->priority instanceof DocumentPriorityEnum ? $this->priority->name : $this->priority, 'pet_id' => $this->pet_id, 'requester' => $this->relationLoaded('requester') ? optional($this->requester)->only(['id','fullname']) : null, 'submitted_at' => $this->submitted_at, 'processing_deadline' => $this->processing_deadline, 'primary_files' => $this->relationLoaded('primaryFiles') ? $this->primaryFiles->map(function ($file) { return [ 'id' => $file->id, 'filename' => $file->filename, 'mime_type' => $file->mime_type, ]; }) : [], 'history_files' => $this->relationLoaded('historyFiles') ? $this->historyFiles->map(function ($file) { return [ 'id' => $file->id, 'filename' => $file->filename, 'mime_type' => $file->mime_type, ]; }) : [], ]; } }