61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use App\Models\IamPrincipal;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
|
|
|
|
|
|
class customer_export implements FromCollection , WithHeadings
|
|
{
|
|
/**
|
|
* @return \Illuminate\Support\Collection
|
|
*/
|
|
|
|
|
|
public function collection(){
|
|
return IamPrincipal::where('principal_type_xid',3)
|
|
->select('first_name',
|
|
'last_name',
|
|
'email_address',
|
|
'date_of_birth',
|
|
'state_xid',
|
|
'phone_number'
|
|
)
|
|
->get()
|
|
->map(function ($customer) {
|
|
return [
|
|
'first_name' => $customer->first_name,
|
|
'last_name' => $customer->last_name,
|
|
'email_address' => $customer->email_address,
|
|
'date_of_birth'=> \Carbon\Carbon::parse($customer->date_of_birth)->format('m-d-Y'),
|
|
'state_xid' => $customer->state->name ?? '', // Access the state name and handle null
|
|
'phone_number' => $customer->phone_number,
|
|
];
|
|
});
|
|
|
|
|
|
}
|
|
|
|
//function header in excel
|
|
public function headings(): array
|
|
{
|
|
return [
|
|
'first_name',
|
|
'last_name',
|
|
'email_address',
|
|
'date_of_birth',
|
|
'state_name',
|
|
'phone_number'
|
|
];
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|