8000 [11.x] Fluent Array validation by Ahmad-Mohammad-Kouja · Pull Request #54517 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[11.x] Fluent Array validation #54517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update the method explodeExplicitRule to support Customizable Array V…
…alidation
  • Loading branch information
Ahmad-Mohammad-Kouja committed Feb 9, 2025
commit f07fd46ea0941370fb7cf5be3e552c748f006cf0
3 changes: 2 additions & 1 deletion src/Illuminate/Validation/ValidationRuleParser.php
< 8000 td class="blob-num blob-num-deletion empty-cell">
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Validation\Rules\ArrayRule;
use Illuminate\Validation\Rules\Date;
use Illuminate\Validation\Rules\Exists;
use Illuminate\Validation\Rules\Numeric;
Expand Down Expand Up @@ -100,7 +101,7 @@ protected function explodeExplicitRule($rule, $attribute)
$rules = [];

foreach ($rule as $value) {
if ($value instanceof Date || $value instanceof Numeric) {
if ($value instanceof Date || $value instanceof Numeric || $value instanceof ArrayRule) {
$rules = array_merge($rules, explode('|', (string) $value));
} else {
$rules[] = $this->prepareRule($value, $attribute);
Expand Down
49 changes: 49 additions & 0 deletions tests/Validation/ValidationArrayRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,54 @@ public function testArrayValidation()
['foo' => (string) Rule::array()->contains(1)]
);
$this->assertTrue($v->passes());

$v = new Validator(
$trans,
['foo' => [1, 2, 3]],
['foo' => ['required', Rule::array()->list()]]
);
$this->assertTrue($v->passes());

$v = new Validator(
$trans,
['foo' => [1, 2, 3]],
['foo' => ['required', Rule::array()->max(3)]]
);
$this->assertTrue($v->passes());

$v = new Validator(
$trans,
['foo' => [1, 2, 3]],
['foo' => ['required', Rule::array()->min(3)]]
);
$this->assertTrue($v->passes());

$v = new Validator(
$trans,
['foo' => [1, 2, 3]],
['foo' => ['required', Rule::array()->between(3, 5)]]
);
$this->assertTrue($v->passes());

$v = new Validator(
$trans,
['foo' => [1, 2, 3]],
['foo' => ['required', Rule::array()->size(3)]]
);
$this->assertTrue($v->passes());

$v = new Validator(
$trans,
['foo' => [1, 2, 3]],
['foo' => ['required', Rule::array()->distinct()]]
);
$this->assertTrue($v->passes());

$v = new Validator(
$trans,
['foo' => [1, 2, 3]],
['foo' => ['required', Rule::array()->contains(1)]]
);
$this->assertTrue($v->passes());
}
}
0