errors[] = 'Kolom ' . $column . ' pada baris ' . $this->rowCount . ' tidak boleh kosong.'; return null; // Abaikan data dengan kolom yang tidak sesuai } } $user = Auth::user(); $existingPeti = Peti::where('fix_lot', $row['fix_lot'])->first(); if ($existingPeti) { $this->errors[] = new MessageBag(['Row ' . $this->rowCount => 'Data Peti sudah ada dalam database.']); return null; } $tipePeti = Type_peti::firstOrCreate( ['type' => $row['tipe_peti_id']], ['size_peti' => 'Default Size', 'description' => 'Default Description'] ); $customer = Customer::firstOrCreate( ['name' => $row['customer_id']], ['code_customer' => 'Default Code', 'lot_no' => 'Default Lot No', 'no_tlp' => 'Default No Tlp', 'address' => 'Default Address'] ); $warehouse = m_warehouse::firstOrCreate( ['name' => $row['warehouse_id']], ['description' => 'Default Description', 'address' => 'Default Address'] ); $kondisiPeti = Kondisi_Peti::firstOrCreate( ['nama_kondisi' => $row['kondisipeti_id']], ['deskripsi_kondisi' => 'Default Deskripsi'] ); $this->rowCount++; return new Peti([ 'created_by' => $user->fullname, 'tipe_peti_id' => $tipePeti->id, 'warna' => $row['warna'], 'customer_id' => $customer->id, 'warehouse_id' => $warehouse->id, 'date_pembuatan' => now(), 'kondisipeti_id' => $kondisiPeti->id, 'packing_no' => $row['packing_no'], 'fix_lot' => $row['fix_lot'], 'status' => $row['status'], ]); } public function registerEvents(): array { return [ AfterImport::class => function (AfterImport $event) { $importedData = $event->getReader()->getDelegate()->getActiveSheet()->toArray(); $filteredData = array_filter($importedData, function ($row) { return $row[0] !== null; }); $event->getReader()->getDelegate()->getActiveSheet()->fromArray($filteredData); }, ]; } public function getErrors() { return $this->errors; } public function getRowCount() { return $this->rowCount; } }