|
| 1 | +## All |
| 2 | + |
| 3 | +Validates every element of an `array` with a set of rules. |
| 4 | + |
| 5 | +## Basic Usage |
| 6 | + |
| 7 | +```php |
| 8 | +Validator::all([Validator::greatarThan(1), Validator::lessThan(10)])->validate([4, 5, 6]); // true |
| 9 | +Validator::all([Validator::greaterThan(1)->lessThan(10)])->validate([4, 5, 6]); // true |
| 10 | + |
| 11 | +Validator::all([Validator::greatarThan(1), Validator::lessThan(10)])->validate([4, 5, 20]); // false |
| 12 | +``` |
| 13 | + |
| 14 | +> **Note** |
| 15 | +> An `UnexpectedValueException` will be thrown if a `constraints` element does not implement a `RuleInterface`. |
| 16 | +
|
| 17 | +> **Note** |
| 18 | +> An `UnexpectedValueException` will be thrown when value to be validated is not an `array`. |
| 19 | +
|
| 20 | +## Options |
| 21 | + |
| 22 | +### `constraints` |
| 23 | + |
| 24 | +type: `array` `required` |
| 25 | + |
| 26 | +Collection of rules, or validators, to validate each element of an `array`. |
| 27 | +Each element must implement a `RuleInterface`, so it is possible to use a single rule or a full validator set of rules. |
| 28 | + |
| 29 | +### `message` |
| 30 | + |
| 31 | +type: `string` default: `At "{{ key }}": {{ message }}` |
| 32 | + |
| 33 | +Message that will be shown if at least one element of an array is invalid according to the given constraints. |
| 34 | +Check the [Custom Messages]() section for more information. |
| 35 | + |
| 36 | +```php |
| 37 | +Validator::all([Validator::notBlank()])->assert([1, 2, ''], 'Test'); |
| 38 | +// Throws: At "2": The "Test" value should not be blank, "" given. |
| 39 | +``` |
| 40 | + |
| 41 | +The following parameters are available: |
| 42 | + |
| 43 | +| Parameter | Description | |
| 44 | +|-----------------|---------------------------------------| |
| 45 | +| `{{ value }}` | The current invalid array value | |
| 46 | +| `{{ name }}` | Name of the value being validated | |
| 47 | +| `{{ key }}` | The array key of the invalid value | |
| 48 | +| `{{ message }}` | The rule message of the invalid value | |
0 commit comments