files->mapToGroups(function($file) { return [Str::slug($file->type, '_') => $file]; }); $serviceData = Service::where('code', $this->service_code)->first(); $organization = Organization::where('id', $this->organization_id)->first(); $organizationName = '-'; if ($organization){ $organizationName = $organization->name; } if ($serviceData) { $serviceName = $serviceData->name; } else { $serviceName = $this->service_code; } if ($this->status == 'approved' && $this->status_final_log ){ $status = 'Done'; } else if ($this->status == 'declined' || $this->status_final_log == 'declined') { $status = 'Declined'; } else { $status = 'Ongoing'; } return [ 'id' => $this->id, 'admission_date' => $this->submission_date ?? null, 'discharge_date' => $this->discharge_date ?? null, 'code' => $this->code ?? null, 'provider_name' => $organizationName ?? null, 'service_type' => $serviceName, 'status' => $status, 'files_by_type' => $filesGroupByType ]; } }