Skip to content

Commit

Permalink
Move getting valid data to the top
Browse files Browse the repository at this point in the history
  • Loading branch information
emsifa committed Nov 27, 2018
1 parent 8854882 commit 05f2bf7
Showing 1 changed file with 42 additions and 43 deletions.
85 changes: 42 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,48 @@ Get count messages.
Check if given key has an error. It returns `bool` if a key has an error, and otherwise.


## Getting Validated, Valid, and Invalid Data

For example you have validation like this:

```php
$validation = $validator->validate([
'title' => 'Lorem Ipsum',
'body' => 'Lorem ipsum dolor sit amet ...',
'published' => null,
'something' => '-invalid-'
], [
'title' => 'required',
'body' => 'required',
'published' => 'default:1|required|in:0,1',
'something' => 'required|numeric'
]);
```

You can get validated data, valid data, or invalid data using methods in example below:

```php
$validatedData = $validation->getValidatedData();
// [
// 'title' => 'Lorem Ipsum',
// 'body' => 'Lorem ipsum dolor sit amet ...',
// 'published' => '1' // notice this
// 'something' => '-invalid-'
// ]

$validData = $validation->getValidData();
// [
// 'title' => 'Lorem Ipsum',
// 'body' => 'Lorem ipsum dolor sit amet ...',
// 'published' => '1'
// ]

$invalidData = $validation->getInvalidData();
// [
// 'something' => '-invalid-'
// ]
```

## Available Rules

> Click to show details.
Expand Down Expand Up @@ -1060,46 +1102,3 @@ class YourCustomRule extends Rule implements BeforeValidate
...
}
```

## Getting Validated, Valid, and Invalid Data

For example you have validation like this:

```php
$validation = $validator->validate([
'title' => 'Lorem Ipsum',
'body' => 'Lorem ipsum dolor sit amet ...',
'published' => null,
'something' => '-invalid-'
], [
'title' => 'required',
'body' => 'required',
'published' => 'default:1|required|in:0,1',
'something' => 'required|numeric'
]);
```

You can get validated data, valid data, or invalid data using methods in example below:

```php
$validatedData = $validation->getValidatedData();
// [
// 'title' => 'Lorem Ipsum',
// 'body' => 'Lorem ipsum dolor sit amet ...',
// 'published' => '1' // notice this
// 'something' => '-invalid-'
// ]

$validData = $validation->getValidData();
// [
// 'title' => 'Lorem Ipsum',
// 'body' => 'Lorem ipsum dolor sit amet ...',
// 'published' => '1'
// ]

$invalidData = $validation->getInvalidData();
// [
// 'something' => '-invalid-'
// ]
```

0 comments on commit 05f2bf7

Please sign in to comment.