From 8625bc695f9b68caa2178548039b037229b98eff Mon Sep 17 00:00:00 2001 From: Jacky Chen Date: Sat, 5 Aug 2023 21:33:26 +0800 Subject: [PATCH] Add `Null` value support for `RequiredUnless` Validation --- src/Attributes/Validation/RequiredUnless.php | 4 ++-- tests/Datasets/Attributes/RulesDataset.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Attributes/Validation/RequiredUnless.php b/src/Attributes/Validation/RequiredUnless.php index 6cc607ce..866ea753 100644 --- a/src/Attributes/Validation/RequiredUnless.php +++ b/src/Attributes/Validation/RequiredUnless.php @@ -17,8 +17,8 @@ class RequiredUnless extends StringValidationAttribute implements RequiringRule protected string|array $values; public function __construct( - string|FieldReference $field, - array|string|BackedEnum|RouteParameterReference ...$values + string|FieldReference $field, + null|array|string|BackedEnum|RouteParameterReference ...$values ) { $this->field = $this->parseFieldReference($field); $this->values = Arr::flatten($values); diff --git a/tests/Datasets/Attributes/RulesDataset.php b/tests/Datasets/Attributes/RulesDataset.php index 5fe9e2fb..d91fc8f9 100644 --- a/tests/Datasets/Attributes/RulesDataset.php +++ b/tests/Datasets/Attributes/RulesDataset.php @@ -896,6 +896,10 @@ function requiredUnlessAttributes(): Generator attribute: new RequiredUnless('field', 'key', 'other'), expected: 'required_unless:field,key,other', ); + yield fixature( + attribute: new RequiredUnless('key', 'null'), + expected: 'required_unless:key,null', + ); } function requiredWithAttributes(): Generator