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.
44 lines
1.0 KiB
44 lines
1.0 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() |
|
{ |
|
$nomor = 1; |
|
// Ambil data dari model Peti |
|
$kondisipetis = Kondisi_Peti::select( |
|
'id', |
|
'nama_kondisi', |
|
'deskripsi_kondisi', |
|
)->get(); |
|
|
|
// Modifikasi data dan tambahkan nomor |
|
$data = $kondisipetis->map(function ($kondisipeti) use (&$nomor) { |
|
return [ |
|
'No' => $nomor++, |
|
'Kondisi Peti' => $kondisipeti->nama_kondisi, |
|
'Deskripsi' => $kondisipeti->deskripsi_kondisi, |
|
]; |
|
}); |
|
|
|
return $data; |
|
} |
|
|
|
public function headings(): array |
|
{ |
|
return [ |
|
'No', |
|
'KONDISI PETI', |
|
'DESKRIPSI', |
|
]; |
|
} |
|
}
|
|
|