24 lines
727 B
PHP
24 lines
727 B
PHP
<?php
|
|
|
|
namespace App\Imports;
|
|
|
|
use App\Models\Medicine;
|
|
use Maatwebsite\Excel\Concerns\ToModel;
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
|
|
|
class MedicineImport implements ToModel, WithHeadingRow
|
|
{
|
|
/**
|
|
* Memetakan setiap baris Excel ke Model Medicine.
|
|
*/
|
|
public function model(array $row)
|
|
{
|
|
return new Medicine([
|
|
'nama_obat' => $row['nama_obat'],
|
|
'qty' => (float) $row['stok'], // Mendukung desimal (ml)
|
|
'unit' => $row['satuan'] ?? 'Pcs',
|
|
'expired_date' => isset($row['kadaluarsa']) ? \Carbon\Carbon::parse($row['kadaluarsa']) : null,
|
|
// Kategori akan terisi otomatis oleh logic Model 'booted'
|
|
]);
|
|
}
|
|
} |