Feature #4 : Villages

This commit is contained in:
Daeng Deni Mardaeni
2024-08-10 20:12:04 +07:00
parent f1a1f23b12
commit d73a006ce0
15 changed files with 84312 additions and 7 deletions

View File

@@ -0,0 +1,49 @@
<?php
namespace Modules\Location\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Modules\Location\Models\Village;
class VillagesExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping
{
public function collection(){
return Village::with('district.city.province')->get();
}
public function map($row): array{
return [
$row->id,
$row->code,
$row->name,
$row->postal_code,
$row->district->name,
$row->district->city->name,
$row->district->city->province->name,
$row->created_at
];
}
public function headings(): array{
return [
'ID',
'Code',
'Name',
'Postal Code',
'District',
'City',
'Province',
'Created At'
];
}
public function columnFormats(): array{
return [
'A' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER,
'D' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER,
'H' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME
];
}
}