customer(); if ($customer === null) { return $this->redirectRoute('settings', navigate: true); } 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 { return $customer->instances() ->whereNotIn('status', ['cancelled', 'deprovisioned']) ->exists(); } private function customer(): ?Customer { $user = auth()->user(); if (! $user) { return null; } return Customer::query()->where('user_id', $user->id)->first() ?? Customer::query()->where('email', $user->email)->first(); } public function render() { $customer = $this->customer(); return view('livewire.confirm-close-account', [ 'blocked' => $customer !== null && $this->hasActivePackage($customer), ]); } }