From 38106a03666ee8b0cd75c60536818e1b4da53485 Mon Sep 17 00:00:00 2001 From: "cuong.tt" Date: Sat, 25 Jan 2025 19:50:15 +0700 Subject: [PATCH 1/3] fix Date Validation rules --- src/Illuminate/Validation/ValidationRuleParser.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Validation/ValidationRuleParser.php b/src/Illuminate/Validation/ValidationRuleParser.php index 0119b6d3a803..9a8d8d3e98c2 100644 --- a/src/Illuminate/Validation/ValidationRuleParser.php +++ b/src/Illuminate/Validation/ValidationRuleParser.php @@ -9,6 +9,7 @@ use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Str; +use Illuminate\Validation\Rules\Date; use Illuminate\Validation\Rules\Exists; use Illuminate\Validation\Rules\Unique; @@ -95,11 +96,11 @@ protected function explodeExplicitRule($rule, $attribute) return Arr::wrap($this->prepareRule($rule, $attribute)); } - return array_map( + return Arr::flatten(array_map( [$this, 'prepareRule'], $rule, array_fill((int) array_key_first($rule), count($rule), $attribute) - ); + )); } /** @@ -126,6 +127,10 @@ protected function prepareRule($rule, $attribute) return $rule; } + if ($rule instanceof Date) { + return explode('|', (string) $rule); + } + if ($rule instanceof NestedRules) { return $rule->compile( $attribute, $this->data[$attribute] ?? null, Arr::dot($this->data), $this->data From cc418fe3a22f33f57e84fc351e3aac666f3a5818 Mon Sep 17 00:00:00 2001 From: "cuong.tt" Date: Sat, 25 Jan 2025 20:51:41 +0700 Subject: [PATCH 2/3] fix Date Validation rules --- .../Validation/ValidationRuleParser.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Illuminate/Validation/ValidationRuleParser.php b/src/Illuminate/Validation/ValidationRuleParser.php index 9a8d8d3e98c2..a483f7880379 100644 --- a/src/Illuminate/Validation/ValidationRuleParser.php +++ b/src/Illuminate/Validation/ValidationRuleParser.php @@ -96,11 +96,18 @@ protected function explodeExplicitRule($rule, $attribute) return Arr::wrap($this->prepareRule($rule, $attribute)); } - return Arr::flatten(array_map( - [$this, 'prepareRule'], - $rule, - array_fill((int) array_key_first($rule), count($rule), $attribute) - )); + $rules = []; + + foreach ($rule as $value) { + if ($value instanceof Date) { + $rules = array_merge($rules, explode('|', (string) $value)); + } + else { + $rules[] = $this->prepareRule($value, $attribute); + } + } + + return $rules; } /** @@ -127,10 +134,6 @@ protected function prepareRule($rule, $attribute) return $rule; } - if ($rule instanceof Date) { - return explode('|', (string) $rule); - } - if ($rule instanceof NestedRules) { return $rule->compile( $attribute, $this->data[$attribute] ?? null, Arr::dot($this->data), $this->data From 509e708c4e93eb91857b8532b567b7c8ae8e88c3 Mon Sep 17 00:00:00 2001 From: "cuong.tt" Date: Sat, 25 Jan 2025 20:57:54 +0700 Subject: [PATCH 3/3] styleci --- src/Illuminate/Validation/ValidationRuleParser.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Illuminate/Validation/ValidationRuleParser.php b/src/Illuminate/Validation/ValidationRuleParser.php index a483f7880379..2d8f5026f091 100644 --- a/src/Illuminate/Validation/ValidationRuleParser.php +++ b/src/Illuminate/Validation/ValidationRuleParser.php @@ -101,8 +101,7 @@ protected function explodeExplicitRule($rule, $attribute) foreach ($rule as $value) { if ($value instanceof Date) { $rules = array_merge($rules, explode('|', (string) $value)); - } - else { + } else { $rules[] = $this->prepareRule($value, $attribute); } }