$row) { if ($key < 5 || !$row[1]) { continue; } $requestArray = [ 'c_pais' => $row[0], 'descripcion' => $row[1], 'formato_de_codigo_postal' => $row[2], 'formato_de_registro_de_identidad_tributaria' => $row[3], 'validacion_del_registro_de_identidad_tributaria' => $row[4], 'agrupaciones' => $row[5], ]; $batchData[] = $requestArray; $processedRows++; if (count($batchData) >= $batchSize) { $this->insertBatch($batchData); $batchData = []; } } if (!empty($batchData)) { $this->insertBatch($batchData); } echo "\n\033[32mImport completed: Processed $processedRows rows.\033[0m\n"; } private function insertBatch(array $batchData) { try { DB::table('sat_pais')->upsert( $batchData, [ 'c_pais', ], [ 'descripcion', 'formato_de_codigo_postal', 'formato_de_registro_de_identidad_tributaria', 'validacion_del_registro_de_identidad_tributaria', 'agrupaciones', ] ); } catch (\Exception $e) { echo "Error in batch: " . $e->getMessage() . "\n"; foreach ($batchData as $row) { echo "Row data: " . json_encode($row) . "\n"; } } } }