Skip to content

Commit

Permalink
[5.x] Support arrays in unique value rules (#10646)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored Aug 16, 2024
1 parent ba1833b commit 3372968
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Rules/UniqueEntryValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
}

$existing = $query
->where($attribute, $value)
->when(
is_array($value),
fn ($query) => $query->whereIn($attribute, $value),
fn ($query) => $query->where($attribute, $value)
)
->first();

if (! $existing) {
Expand Down
6 changes: 5 additions & 1 deletion src/Rules/UniqueTermValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
}

$existing = $query
->where($attribute, $value)
->when(
is_array($value),
fn ($query) => $query->whereIn($attribute, $value),
fn ($query) => $query->where($attribute, $value)
)
->first();

if (! $existing) {
Expand Down
6 changes: 5 additions & 1 deletion src/Rules/UniqueUserValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
$this->column ??= $attribute;

$existing = User::query()
->where($this->column, $value)
->when(
is_array($value),
fn ($query) => $query->whereIn($this->column, $value),
fn ($query) => $query->where($this->column, $value)
)
->first();

if (! $existing) {
Expand Down

0 comments on commit 3372968

Please sign in to comment.