*/ public array $clientOptions = []; public bool $unifiError = false; public static function modalMaxWidth(): string { return 'lg'; } public function mount(UnifiClient $unifi): void { try { $this->clientOptions = collect($unifi->clients()) ->map(fn ($c) => [ 'mac' => strtolower($c->mac ?? ''), 'label' => $c->name ?? $c->hostname ?? ($c->mac ?? '?'), ]) ->filter(fn ($o) => $o['mac'] !== '') ->sortBy('label', SORT_NATURAL | SORT_FLAG_CASE) ->values()->all(); } catch (\Throwable) { $this->unifiError = true; } } public function save() { $this->validate([ 'name' => 'required|string|max:100', 'mac' => ['nullable', 'string', 'max:32', 'unique:persons,mac'], ]); Person::create([ 'name' => $this->name, 'mac' => $this->mac ?: null, 'presence' => 'unknown', ]); $this->closeModal(); return redirect()->route('persons.index'); } public function render() { return view('livewire.modals.add-person'); } }