Feature #3 : Districts
This commit is contained in:
44
app/Exports/DistrictsExport.php
Normal file
44
app/Exports/DistrictsExport.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user