25 lines
720 B
PHP
25 lines
720 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Imports;
|
||
|
|
|
||
|
|
use App\Models\Supply;
|
||
|
|
use Maatwebsite\Excel\Concerns\ToModel;
|
||
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||
|
|
|
||
|
|
class SupplyImport implements ToModel, WithHeadingRow
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Memetakan baris Excel ke Model Supply.
|
||
|
|
* * @param array $row
|
||
|
|
* @return \Illuminate\Database\Eloquent\Model|null
|
||
|
|
*/
|
||
|
|
public function model(array $row)
|
||
|
|
{
|
||
|
|
return new Supply([
|
||
|
|
'nama_perlengkapan' => $row['nama_perlengkapan'], // Harus sesuai header Excel
|
||
|
|
'qty' => $row['qty'],
|
||
|
|
'unit' => $row['unit'],
|
||
|
|
// Kategori dan Category ID akan terisi otomatis oleh logic 'booted' di Model Supply.
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|