Skip to content

Commit 05f2bf7

Browse files
committed
Move getting valid data to the top
1 parent 8854882 commit 05f2bf7

File tree

1 file changed

+42
-43
lines changed

1 file changed

+42
-43
lines changed

README.md

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,48 @@ Get count messages.
384384
Check if given key has an error. It returns `bool` if a key has an error, and otherwise.
385385

386386

387+
## Getting Validated, Valid, and Invalid Data
388+
389+
For example you have validation like this:
390+
391+
```php
392+
$validation = $validator->validate([
393+
'title' => 'Lorem Ipsum',
394+
'body' => 'Lorem ipsum dolor sit amet ...',
395+
'published' => null,
396+
'something' => '-invalid-'
397+
], [
398+
'title' => 'required',
399+
'body' => 'required',
400+
'published' => 'default:1|required|in:0,1',
401+
'something' => 'required|numeric'
402+
]);
403+
```
404+
405+
You can get validated data, valid data, or invalid data using methods in example below:
406+
407+
```php
408+
$validatedData = $validation->getValidatedData();
409+
// [
410+
// 'title' => 'Lorem Ipsum',
411+
// 'body' => 'Lorem ipsum dolor sit amet ...',
412+
// 'published' => '1' // notice this
413+
// 'something' => '-invalid-'
414+
// ]
415+
416+
$validData = $validation->getValidData();
417+
// [
418+
// 'title' => 'Lorem Ipsum',
419+
// 'body' => 'Lorem ipsum dolor sit amet ...',
420+
// 'published' => '1'
421+
// ]
422+
423+
$invalidData = $validation->getInvalidData();
424+
// [
425+
// 'something' => '-invalid-'
426+
// ]
427+
```
428+
387429
## Available Rules
388430

389431
> Click to show details.
@@ -1060,46 +1102,3 @@ class YourCustomRule extends Rule implements BeforeValidate
10601102
...
10611103
}
10621104
```
1063-
1064-
## Getting Validated, Valid, and Invalid Data
1065-
1066-
For example you have validation like this:
1067-
1068-
```php
1069-
$validation = $validator->validate([
1070-
'title' => 'Lorem Ipsum',
1071-
'body' => 'Lorem ipsum dolor sit amet ...',
1072-
'published' => null,
1073-
'something' => '-invalid-'
1074-
], [
1075-
'title' => 'required',
1076-
'body' => 'required',
1077-
'published' => 'default:1|required|in:0,1',
1078-
'something' => 'required|numeric'
1079-
]);
1080-
```
1081-
1082-
You can get validated data, valid data, or invalid data using methods in example below:
1083-
1084-
```php
1085-
$validatedData = $validation->getValidatedData();
1086-
// [
1087-
// 'title' => 'Lorem Ipsum',
1088-
// 'body' => 'Lorem ipsum dolor sit amet ...',
1089-
// 'published' => '1' // notice this
1090-
// 'something' => '-invalid-'
1091-
// ]
1092-
1093-
$validData = $validation->getValidData();
1094-
// [
1095-
// 'title' => 'Lorem Ipsum',
1096-
// 'body' => 'Lorem ipsum dolor sit amet ...',
1097-
// 'published' => '1'
1098-
// ]
1099-
1100-
$invalidData = $validation->getInvalidData();
1101-
// [
1102-
// 'something' => '-invalid-'
1103-
// ]
1104-
```
1105-

0 commit comments

Comments
 (0)