From 016417c512bb93c1323d4c50280523d471340356 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 16 Aug 2024 13:06:59 +0100 Subject: [PATCH 1/3] Support arrays in `UniqueEntryValue` rule --- src/Rules/UniqueEntryValue.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Rules/UniqueEntryValue.php b/src/Rules/UniqueEntryValue.php index b3f7dfd387a..1fc6283d453 100644 --- a/src/Rules/UniqueEntryValue.php +++ b/src/Rules/UniqueEntryValue.php @@ -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) { From 5e97e5ce840ce7d1b1a648506a138ff78323b693 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 16 Aug 2024 13:11:18 +0100 Subject: [PATCH 2/3] Support arrays in `UniqueUserValue` rule --- src/Rules/UniqueUserValue.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Rules/UniqueUserValue.php b/src/Rules/UniqueUserValue.php index a69121cee75..80bfb7cf6da 100644 --- a/src/Rules/UniqueUserValue.php +++ b/src/Rules/UniqueUserValue.php @@ -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) { From 54d1005ffa9a740b40efde7425a6cd7659f3a282 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 16 Aug 2024 13:11:28 +0100 Subject: [PATCH 3/3] Support arrays in `UniqueTermValue` rule --- src/Rules/UniqueTermValue.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Rules/UniqueTermValue.php b/src/Rules/UniqueTermValue.php index 8470a2b9769..32614bcc390 100644 --- a/src/Rules/UniqueTermValue.php +++ b/src/Rules/UniqueTermValue.php @@ -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) {