2015-01-30 09:40:06 +01:00
|
|
|
# Each
|
|
|
|
|
2018-06-17 01:20:47 +02:00
|
|
|
- `Each(Validatable $rule)`
|
2015-01-30 09:40:06 +01:00
|
|
|
|
2018-06-17 01:20:47 +02:00
|
|
|
Validates whether each value in the input is valid according to another rule.
|
2015-01-30 09:40:06 +01:00
|
|
|
|
|
|
|
```php
|
2015-10-18 03:44:47 +02:00
|
|
|
$releaseDates = [
|
2015-01-30 09:40:06 +01:00
|
|
|
'validation' => '2010-01-01',
|
|
|
|
'template' => '2011-01-01',
|
|
|
|
'relational' => '2011-02-05',
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2015-01-30 09:40:06 +01:00
|
|
|
|
2018-06-17 01:20:47 +02:00
|
|
|
v::each(v::dateTime())->validate($releaseDates); // true
|
2015-01-30 09:40:06 +01:00
|
|
|
```
|
|
|
|
|
2018-06-17 01:20:47 +02:00
|
|
|
You can also validate array keys combining this rule with [Call](Call.md):
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::call('array_keys', v::each(v::stringType()))->validate($releaseDates); // true
|
|
|
|
```
|
|
|
|
|
|
|
|
This rule will not validate values that are not iterable, to have a more detailed
|
|
|
|
error message, add [IterableType](IterableType.md) to your chain, for example.
|
|
|
|
|
|
|
|
If the input is empty this rule will consider the value as valid, you use
|
|
|
|
[NotEmpty](NotEmpty.md) if convenient:
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::each(v::dateTime())->validate([]); // true
|
|
|
|
v::notEmpty()->each(v::dateTime())->validate([]); // false
|
|
|
|
```
|
2015-01-30 09:40:06 +01:00
|
|
|
|
2019-05-11 18:32:13 +02:00
|
|
|
## Categorization
|
|
|
|
|
|
|
|
- Arrays
|
|
|
|
- Nesting
|
|
|
|
|
2017-03-27 22:04:13 +02:00
|
|
|
## Changelog
|
|
|
|
|
|
|
|
Version | Description
|
|
|
|
--------|-------------
|
2018-06-17 01:20:47 +02:00
|
|
|
2.0.0 | Remove support for key validation
|
2017-03-27 22:04:13 +02:00
|
|
|
0.3.9 | Created
|
|
|
|
|
2015-08-20 06:38:41 +02:00
|
|
|
***
|
2015-01-30 09:40:06 +01:00
|
|
|
See also:
|
|
|
|
|
2017-03-28 11:53:14 +02:00
|
|
|
- [ArrayVal](ArrayVal.md)
|
2018-06-17 01:20:47 +02:00
|
|
|
- [Call](Call.md)
|
|
|
|
- [IterableType](IterableType.md)
|
|
|
|
- [Key](Key.md)
|
2018-12-11 13:31:50 +01:00
|
|
|
- [NotEmpty](NotEmpty.md)
|
|
|
|
- [Unique](Unique.md)
|