Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 3641d1b

Browse files
committed
chore: updated EachValue rule documentation
1 parent 09f3dbd commit 3641d1b

File tree

3 files changed

+51
-62
lines changed

3 files changed

+51
-62
lines changed

docs/03-rules.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- [Comparison Rules](#comparison-rules)
55
- [Date Rules](#date-rules)
66
- [Choice Rules](#choice-rules)
7-
- [Other Rules](#other-rules)
7+
- [Iterable Rules](#iterable-rules)
88

99
## Basic Rules
1010

@@ -28,6 +28,6 @@
2828
- [Choice](03x-rules-choice.md)
2929
- [Country](03x-rules-country.md)
3030

31-
## Other Rules
31+
## Iterable Rules
3232

33-
- [All](03x-rules-all.md)
33+
- [EachValue](03x-rules-eachvalue.md)

docs/03x-rules-all.md

Lines changed: 0 additions & 59 deletions
This file was deleted.

docs/03x-rules-eachvalue.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## EachValue
2+
3+
Validates every element of an `array` or object implementing `\Traversable` with a given set of rules.
4+
5+
```php
6+
EachValue(
7+
Validator $validator,
8+
string $message = 'At key "{{ key }}": {{ message }}'
9+
);
10+
```
11+
12+
## Basic Usage
13+
14+
```php
15+
Validator::eachValue(Validator::notBlank()->greaterThan(1)->lessThan(10))->validate([4, 5, 6]); // true
16+
Validator::eachValue(Validator::notBlank()->greaterThan(1)->lessThan(10))->validate([4, 5, 20]); // false
17+
```
18+
19+
> **Note**
20+
> An `UnexpectedValueException` will be thrown when the input value is not an `array` or an object implementing `\Traversable`.
21+
22+
## Options
23+
24+
### `validator`
25+
26+
type: `Validator` `required`
27+
28+
Validator that will validate each element of an `array` or object implementing `\Traversable`.
29+
30+
### `message`
31+
32+
type: `string` default: `At "{{ key }}": {{ message }}`
33+
34+
Message that will be shown if at least one input value element is invalid according to the given `validator`.
35+
36+
```php
37+
Validator::all(Validator::notBlank())->assert(['red', 'green', ''], 'Test');
38+
// Throws: At key "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 value |
46+
| `{{ name }}` | Name of the invalid value |
47+
| `{{ key }}` | The array key of the invalid array element |
48+
| `{{ message }}` | The rule message of the invalid array element |

0 commit comments

Comments
 (0)