From fafd157bcf005fa5bbd54e5fbfbe8326a48d8add Mon Sep 17 00:00:00 2001 From: Tommy Stigen Olsen Date: Mon, 18 Sep 2023 09:29:53 +0200 Subject: [PATCH] Fix uniqueness constraint validation on Attribute Group edit (#1246) --- .../Components/Settings/Attributes/AttributeGroupEdit.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/admin/src/Http/Livewire/Components/Settings/Attributes/AttributeGroupEdit.php b/packages/admin/src/Http/Livewire/Components/Settings/Attributes/AttributeGroupEdit.php index ef7053ac52..441c588c12 100644 --- a/packages/admin/src/Http/Livewire/Components/Settings/Attributes/AttributeGroupEdit.php +++ b/packages/admin/src/Http/Livewire/Components/Settings/Attributes/AttributeGroupEdit.php @@ -76,10 +76,16 @@ public function create() $handle = Str::handle("{$this->typeHandle}_{$this->attributeGroup->translate('name')}"); $this->attributeGroup->handle = $handle; + $uniquenessConstraint = 'unique:' . get_class($this->attributeGroup) . ',handle'; + if ($this->attributeGroup->id) { + $uniquenessConstraint .= ',' . $this->attributeGroup->id; + } + $this->validate([ - 'attributeGroup.handle' => 'unique:'.get_class($this->attributeGroup).',handle,'.$this->attributeGroup->id, + 'attributeGroup.handle' => $uniquenessConstraint, ]); + if ($this->attributeGroup->id) { $this->attributeGroup->save(); $this->emit('attribute-group-edit.updated', $this->attributeGroup->id);