get(); $data = $data->map(function ($item) { if (in_array($item->city_code, ['92.01', '92.04', '92.05', '92.09', '92.10', '92.71'])) { $item->province_name = Province::where('code', '92.1')->first()->name; } else { $item->province_name = $item->city->province->name; } return $item; }); } public function map($row): array{ return [ $row->id, $row->code, $row->name, $row->city->name, $row->province_name, $row->created_at ]; } public function headings(): array{ return [ 'ID', 'Code', 'Name', 'City', 'Province', 'Created At' ]; } public function columnFormats(): array{ return [ 'A' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER, 'F' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME ]; } }