*/ public function toArray($request): array { return [ 'id' => $this->id, 'employee_id' => $this->employee_id, 'employee_name' => $this->when( $this->relationLoaded('employee'), $this->employee->full_name ?? ($this->employee->first_name . ' ' . $this->employee->last_name) ), 'diploma_number' => $this->diploma_number, 'diploma_date' => $this->diploma_date?->format('Y-m-d'), 'authorization_number' => $this->authorization_number, 'authorization_issue_date' => $this->authorization_issue_date?->format('Y-m-d'), 'authorization_expiry_date' => $this->authorization_expiry_date?->format('Y-m-d'), 'notes' => $this->notes, 'is_authorization_valid' => $this->is_authorization_valid, '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 'employee' => $this->when( $this->relationLoaded('employee'), new EmployeeResource($this->employee) ), 'documents' => $this->when( $this->relationLoaded('documents'), PractitionerDocumentResource::collection($this->documents) ), ]; } }