Skip to content

Commit c0709ca

Browse files
committed
Fix bug, constraint fields being wrongly applied.
1 parent f671841 commit c0709ca

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/HasUniqueNames.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ public function getUniqueValue(string $uniqueField, array $constraintFields, str
159159
$nextN = $maxN + 1;
160160
$newValue = $base.str_replace('{n}', $nextN, $suffixFormat);
161161

162-
while (self::where($constraintFields)->where($uniqueField, $newValue)->exists()) {
162+
$query = self::query();
163+
foreach ($constraintFields as $field) {
164+
$query->where($field, $constraintValues[$field]);
165+
}
166+
while ($query->where($uniqueField, $newValue)->exists()) {
163167
$nextN++;
164168
$newValue = $base.str_replace('{n}', $nextN, $suffixFormat);
165169
}

0 commit comments

Comments
 (0)