customer(); // No customer behind this login (e.g. an operator account) — say so // instead of leaving the button looking broken. if ($customer === null) { $this->addError('confirmWord', __('dashboard.no_customer_action')); return null; } if ($this->hasActivePackage($customer)) { $this->addError('confirmWord', __('settings.close_blocked')); return; } if (mb_strtoupper(trim($this->confirmWord)) !== __('settings.close_keyword')) { $this->addError('confirmWord', __('settings.close_mismatch')); return; } $customer->update(['closed_at' => now(), 'status' => 'closed']); return $this->redirectRoute('settings', navigate: true); } private function hasActivePackage(Customer $customer): bool { // Only genuinely-live packages block closure — a failed/cancelled/ // deprovisioned instance does not retain a service. return $customer->instances() ->whereIn('status', ['active', 'provisioning', 'cancellation_scheduled']) ->exists(); } public function render() { $customer = $this->customer(); return view('livewire.confirm-close-account', [ 'blocked' => $customer !== null && $this->hasActivePackage($customer), ]); } }