os = $server->os_id; $this->checkProtectedStatus(); } protected function checkProtectedStatus(): void { try { $proxmox = new Proxmox; $config = $proxmox->request('/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/config')->json()['data'] ?? []; // Protected can be 1, '1', true, or missing/null $this->isProtected = isset($config['protection']) && ($config['protection'] == 1 || $config['protection'] === '1' || $config['protection'] === true); } catch (\Throwable $e) { // If we can't check, assume not protected $this->isProtected = false; } } public function reinstall() { // Check protected status again before proceeding $this->checkProtectedStatus(); if ($this->isProtected) { $this->notify('Cannot reinstall: This server is protected in Proxmox', 'error'); return; } $this->validate([ 'os' => 'required', ]); if (!$this->confirmReinstall) { $this->notify('Please confirm the reinstall', 'error'); return; } $this->server->os_id = $this->os; $this->server->save(); $proxmox = new Proxmox; $proxmox->reinstall($this->server); sleep(10); $this->redirect('https://billing.virtnet.bond/servers/', true); } public function render() { // assuming Server has relation `node()` → Node model $locationId = $this->server->node->location_id; $osList = \Paymenter\Extensions\Servers\Proxmox\Models\Location::findOrFail($locationId) ->os() ->get(); return view('proxmox::reinstall', [ 'osList' => $osList, 'isProtected' => $this->isProtected, ]); } }