Skip to content

Commit

Permalink
Fix uniqueness constraint validation on Attribute Group edit (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommysolsen authored and alecritson committed Sep 21, 2023
1 parent bc58dfa commit 63cd50c
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 63cd50c

Please sign in to comment.