authorize('datacenters.manage'); $dc = Datacenter::query()->where('uuid', $uuid)->first(); if ($dc === null) { return; } $this->editingUuid = $uuid; $this->editName = $dc->name; $this->editLocation = (string) $dc->location; } public function cancelEdit(): void { $this->reset('editingUuid', 'editName', 'editLocation'); } public function update(): void { $this->authorize('datacenters.manage'); if ($this->editingUuid === null) { return; } $data = $this->validate([ 'editName' => 'required|string|max:255', 'editLocation' => 'nullable|string|max:255', ]); Datacenter::query()->where('uuid', $this->editingUuid)->update([ 'name' => $data['editName'], 'location' => $data['editLocation'] ?: null, ]); $this->cancelEdit(); $this->dispatch('notify', message: __('datacenters.updated')); } public function save(): void { $this->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(), ]); } }