You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
<?php |
|
|
|
namespace App\Exports; |
|
|
|
use App\Models\Customer; |
|
use Maatwebsite\Excel\Concerns\WithHeadings; |
|
use Maatwebsite\Excel\Concerns\FromCollection; |
|
|
|
class CustomerExport implements FromCollection, WithHeadings |
|
{ |
|
/** |
|
* @return \Illuminate\Support\Collection |
|
*/ |
|
public function collection() |
|
{ |
|
// Ambil data dari model Peti |
|
$customers = Customer::select( |
|
'id', |
|
'name', |
|
'code_customer', |
|
'lot_no', |
|
'no_tlp', |
|
'address' |
|
)->get(); |
|
|
|
// Modifikasi data dan tambahkan nomor |
|
$data = $customers->map(function ($customer) use (&$nomor) { |
|
return [ |
|
'No' => $customer->id, |
|
'Nama Customer' => $customer->name, |
|
'Kode Customer' => $customer->code_customer, |
|
'Lot No' => $customer->lot_no, |
|
'No Telepon' => $customer->no_tlp, |
|
'Alamat' => $customer->address, |
|
]; |
|
}); |
|
|
|
return $data; |
|
} |
|
|
|
public function headings(): array |
|
{ |
|
return [ |
|
'No', |
|
'NAMA CUSTOMER', |
|
'kODE CUSTOMER', |
|
'LOT NO', |
|
'NO TELEPONE', |
|
'ALAMAT', |
|
]; |
|
} |
|
}
|
|
|