Skip to content

Commit

Permalink
fix the method explodeExplicitRule to support Numeric Validation (#54478
Browse files Browse the repository at this point in the history
)

Co-authored-by: cuong.tt <cuong.tt@gmail.com>
  • Loading branch information
mrvipchien and cuong.tt authored Feb 5, 2025
1 parent 4d010eb commit a279f59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Illuminate/Validation/ValidationRuleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Support\Str;
use Illuminate\Validation\Rules\Date;
use Illuminate\Validation\Rules\Exists;
use Illuminate\Validation\Rules\Numeric;
use Illuminate\Validation\Rules\Unique;

class ValidationRuleParser
Expand Down Expand Up @@ -99,7 +100,7 @@ protected function explodeExplicitRule($rule, $attribute)
$rules = [];

foreach ($rule as $value) {
if ($value instanceof Date) {
if ($value instanceof Date || $value instanceof Numeric) {
$rules = array_merge($rules, explode('|', (string) $value));
} else {
$rules[] = $this->prepareRule($value, $attribute);
Expand Down
10 changes: 10 additions & 0 deletions tests/Validation/ValidationNumericRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ public function testNumericValidation()
);

$this->assertEmpty($validator->errors()->first('numeric'));

$rule = Rule::numeric()->exactly(10);

$validator = new Validator(
$trans,
['numeric' => 10],
['numeric' => [$rule]]
);

$this->assertEmpty($validator->errors()->first('numeric'));
}

public function testUniquenessValidation()
Expand Down

0 comments on commit a279f59

Please sign in to comment.