authorize('datacenters.manage'); // modals are reachable without the route middleware $dc = Datacenter::query()->where('uuid', $uuid)->firstOrFail(); $this->uuid = $uuid; $this->code = $dc->code; $this->name = $dc->name; $this->location = (string) $dc->location; $this->originalLocation = (string) $dc->location; } public function save() { $this->authorize('datacenters.manage'); // Accept the configured countries plus the record's own legacy value, so a // datacenter created before the curated list can still be edited. The // legacy value is read from the DB — never from the client-hydrated // property, which could be forged to whitelist an arbitrary location. $dc = Datacenter::query()->where('uuid', $this->uuid)->firstOrFail(); $allowed = array_keys((array) config('countries')); if ($dc->location) { $allowed[] = $dc->location; } $data = $this->validate([ 'name' => 'required|string|max:255', 'location' => 'nullable|in:'.implode(',', $allowed), ]); Datacenter::query()->where('uuid', $this->uuid)->update([ 'name' => $data['name'], 'location' => $data['location'] ?: null, ]); $this->dispatch('notify', message: __('datacenters.updated')); return $this->redirectRoute('admin.datacenters', navigate: true); } public function render() { return view('livewire.admin.edit-datacenter', [ 'countries' => config('countries'), ]); } }