50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
|
<?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
|
||
|
];
|
||
|
}
|
||
|
}
|