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.
46 lines
1.1 KiB
46 lines
1.1 KiB
<?php |
|
|
|
namespace App\Exports; |
|
|
|
use App\Models\Kondisi_Peti; |
|
use Maatwebsite\Excel\Concerns\WithHeadings; |
|
use Maatwebsite\Excel\Concerns\FromCollection; |
|
|
|
class KondisiPetiExport implements FromCollection, WithHeadings |
|
{ |
|
/** |
|
* @return \Illuminate\Support\Collection |
|
*/ |
|
public function collection() |
|
{ |
|
// Ambil data dari model Peti |
|
$kondisipetis = Kondisi_Peti::select( |
|
'id', |
|
'nama_kondisi', |
|
'deskripsi_kondisi', |
|
)->get(); |
|
|
|
// Inisialisasi nomor awal |
|
// $nomor = 1; |
|
|
|
// Modifikasi data dan tambahkan nomor |
|
$data = $kondisipetis->map(function ($kondisipeti) use (&$nomor) { |
|
return [ |
|
'No' => $kondisipeti->id, |
|
'Nama Kondisi' => $kondisipeti->nama_kondisi, |
|
'Deskripsi' => $kondisipeti->deskripsi_kondisi, |
|
]; |
|
}); |
|
|
|
return $data; |
|
} |
|
|
|
public function headings(): array |
|
{ |
|
return [ |
|
'No', |
|
'NAMA KONDISI', |
|
'DESKRIPSI', |
|
]; |
|
} |
|
}
|
|
|