*/ public function toArray($request): array { return [ 'id' => $this->id, 'deceased_id' => $this->deceased_id, 'doc_type' => $this->doc_type, 'file_id' => $this->file_id, 'generated_at' => $this->generated_at?->format('Y-m-d H:i:s'), 'created_at' => $this->created_at?->format('Y-m-d H:i:s'), 'updated_at' => $this->updated_at?->format('Y-m-d H:i:s'), // Relations 'deceased' => $this->when( $this->relationLoaded('deceased'), function () { return [ 'id' => $this->deceased->id, 'first_name' => $this->deceased->first_name, 'last_name' => $this->deceased->last_name, 'full_name' => $this->deceased->first_name . ' ' . $this->deceased->last_name, 'date_of_birth' => $this->deceased->date_of_birth?->format('Y-m-d'), 'date_of_death' => $this->deceased->date_of_death?->format('Y-m-d'), ]; } ), 'file' => $this->when( $this->relationLoaded('file'), function () { return $this->file ? [ 'id' => $this->file->id, 'filename' => $this->file->filename ?? null, 'path' => $this->file->path ?? null, 'mime_type' => $this->file->mime_type ?? null, 'size' => $this->file->size ?? null, ] : null; } ), ]; } }