Created
January 12, 2019 03:42
-
-
Save akmalhazim/5e7f14bcfcba685935cfe9d67c7b3b1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Exports; | |
use App\StudentOnly; | |
use Maatwebsite\Excel\Concerns\FromCollection; | |
use PhpOffice\PhpSpreadsheet\Style\NumberFormat; | |
use Maatwebsite\Excel\Concerns\WithHeadings; | |
use Maatwebsite\Excel\Concerns\WithColumnFormatting; | |
use Maatwebsite\Excel\Concerns\WithMapping; | |
class StudentsExport implements FromCollection, WithHeadings, WithMapping, WithColumnFormatting | |
{ | |
/** | |
* @return \Illuminate\Support\Collection | |
*/ | |
public function collection() | |
{ | |
return StudentOnly::with(['class_location_obj', 'belt_obj', 'subscription'])->get(); | |
} | |
/** | |
* @var Invoice $invoice | |
*/ | |
public function map($student): array | |
{ | |
// dd($student->subscription['max_period']); | |
// dd($student->registered_at->format('F')); | |
return [ | |
$student->name, | |
" 0005", | |
// (string) $student->identification_card_number, | |
$student->home_address, | |
$student->city, | |
$student->postal_code, | |
$student->state, | |
$student->country, | |
\Carbon\Carbon::parse($student->birthday_date)->toFormattedDateString(), | |
$student->gender == 1 ? 'Male' : 'Female', | |
$student->school_name, | |
$student->class_location_obj['location'], | |
$student->belt_obj['name'], | |
$student->registered_at->format('F'), | |
$student->is_gym ? 'Ya' : '', | |
$student->remark | |
]; | |
} | |
public function headings(): array | |
{ | |
return [ | |
'Nama', | |
'No. IC', | |
'Alamat Rumah', | |
'Daerah', | |
'Poskod', | |
'Negeri', | |
'Negara', | |
'Tarikh Lahir', | |
'Jantina', | |
'Sekolah / Tempat Bekerja', | |
'Lokasi Kelas', | |
'Tali Pinggang', | |
'Bulan Masuk', | |
'Champion Kelas', | |
'Remark' | |
]; | |
} | |
public function columnFormats(): array | |
{ | |
return [ | |
'B' => '000000000000' | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment