user()->isAdmin(), 403); } public function edit(int $id): void { $model = Priority::query()->findOrFail($id); $this->editingId = $model->id; $this->name = $model->name; $this->colorHex = $model->color_hex; $this->level = $model->level; } public function save(): void { $levelRule = Rule::unique('priorities', 'level'); if ($this->editingId) { $levelRule = $levelRule->ignore($this->editingId); } $this->validate([ 'name' => ['required', 'string', 'max:255'], 'colorHex' => ['required', 'regex:/^#[0-9A-Fa-f]{6}$/'], 'level' => ['required', 'integer', 'between:1,4', $levelRule], ]); Priority::query()->updateOrCreate( ['id' => $this->editingId], ['name' => $this->name, 'color_hex' => $this->colorHex, 'level' => $this->level] ); $this->reset(['name', 'editingId']); $this->colorHex = '#3B82F6'; $this->level = 1; session()->flash('success', 'Приоритет сохранен.'); } public function delete(int $id): void { Priority::query()->findOrFail($id)->delete(); session()->flash('success', 'Приоритет удален.'); } public function render() { return view('livewire.directories.priorities-page', [ 'items' => Priority::query()->orderBy('level')->get(), ])->title('Справочник: Приоритеты'); } }