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);