files->mapToGroups(function($file) { return [Str::slug($file->type, '_') => $file]; }); $provider = Organization::where('id', $this->organization_id)->first(); $documentQty = File::where(['fileable_type' => 'App\Models\RequestLog', 'fileable_id' => $this->id])->get()->toArray(); $parsedDateTime = Carbon::parse($this->created_at); $formattedDateTime = $parsedDateTime->format('Y-m-d H:i:s'); $timeInsertBenefit = RequestLogBenefit::where('request_log_id', $this->id)->first(); if ($timeInsertBenefit){ $created_final_at = $timeInsertBenefit->created_at; $durationFinalGl = Helper::differenceTime($timeInsertBenefit->created_at, $this->approved_final_log_at); } else { $durationFinalGl = 0; $created_final_at = null; } $durationGl = Helper::differenceTime($formattedDateTime, $this->submission_date); $data = [ 'id' => $this->id, 'code' => $this->code, 'created_at' => $formattedDateTime, 'created_final_at' => $created_final_at, 'submission_date' => $this->submission_date, 'approved_by' => Helper::userName($this->approved_by), 'approved_final_log_at' => $this->approved_final_log_at, 'approved_final_log_by' => $this->final_log == 1 ? Helper::userName($this->approved_final_log_by) : '-', 'service_name' => $this->service ? $this->service->name : '', 'provider' => $provider ? $provider->name : '-', 'document_qty' => count($documentQty), 'status' => $this->status ?? '-', 'status_final_log' => $this->status_final_log ?? '-', 'member_name' => $this->member->name, 'payment_type' => $this->payment_type, 'payment_type_name' => $this->payment_type_name, 'duration_gl' => $durationGl, 'duration_final_gl' => $this->final_log == 1 ? $durationFinalGl : '-', 'files_by_type' => $filesGroupByType, 'time_insert_benefit' => $filesGroupByType, ]; return $data; } }