Skip to content

Commit

Permalink
Fix uniqueness constraint validation when attributeGroup is not persi…
Browse files Browse the repository at this point in the history
…sted
  • Loading branch information
tommysolsen committed Sep 9, 2023
1 parent 8d8bd97 commit ff66c8b
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 ff66c8b

Please sign in to comment.