45 lines
1.1 KiB
PHP
45 lines
1.1 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\District;
|
||
|
|
||
|
class DistrictsExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping
|
||
|
{
|
||
|
public function collection(){
|
||
|
return District::with('city.province')->get();
|
||
|
}
|
||
|
|
||
|
public function map($row): array{
|
||
|
return [
|
||
|
$row->id,
|
||
|
$row->code,
|
||
|
$row->name,
|
||
|
$row->city->name,
|
||
|
$row->city->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
|
||
|
];
|
||
|
}
|
||
|
}
|