client->fetch($dto); } public function save(array $data): void { if (empty($data)) { return; } collect($data) ->chunk(500) ->each(function ($chunk) { $rows = $chunk->map(function (array $row) { return [ 'g_number' => $row['g_number'], 'date' => !empty($row['date']) ? $row['date'] : now(), 'last_change_date' => $row['last_change_date'], 'supplier_article' => $row['supplier_article'], 'tech_size' => $row['tech_size'], 'barcode' => (int)$row['barcode'], 'total_price' => $row['total_price'], 'discount_percent' => $row['discount_percent'], 'warehouse_name' => $row['warehouse_name'], 'oblast' => $row['oblast'], 'income_id' => $row['income_id'], 'odid' => (int)$row['odid'], 'nm_id' => $row['nm_id'], 'subject' => $row['subject'], 'category' => $row['category'], 'brand' => $row['brand'], 'is_cancel' => $row['is_cancel'], 'cancel_dt' => $row['cancel_dt'], 'created_at' => now(), 'updated_at' => now(), ]; })->toArray(); try { Order::insert($rows); } catch (\Throwable $e) { \Log::error('Insert failed', [ 'error' => $e->getMessage(), 'row_sample' => $rows[0] ?? null, ]); throw $e; } }); } }