authorize('datacenters.manage'); // Normalize before validating so the unique check matches how the row is // stored — otherwise `FSN` passes the rule but the lowercased insert collides. $this->code = strtolower(trim($this->code)); $data = $this->validate(); Datacenter::create([ 'code' => $data['code'], 'name' => $data['name'], 'location' => $data['location'] ?: null, 'active' => true, ]); $this->reset('code', 'name', 'location'); $this->dispatch('notify', message: __('datacenters.created')); } public function toggle(string $uuid): void { $this->authorize('datacenters.manage'); $datacenter = Datacenter::query()->where('uuid', $uuid)->first(); $datacenter?->update(['active' => ! $datacenter->active]); } public function render() { return view('livewire.admin.datacenters', [ 'datacenters' => Datacenter::query()->withCount('hosts')->orderBy('name')->get(), 'countries' => config('countries'), ]); } }