Skip to content

Commit

Permalink
- Added simple example to top of README.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
IndexZer0 committed Mar 6, 2024
1 parent e551301 commit 341f503
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,45 @@
- **Conveniently** create and validate data straight from the `ValidationProvider`.

---

## Simple example
- Nesting domain model rules within arrays.

```php
use IndexZer0\LaravelValidationProvider\Facades\ValidationProvider;

class AuthorValidationProvider extends AbstractValidationProvider
{
public function rules(): array
{
return ['name' => ['required'],];
}
}

class BookValidationProvider extends AbstractValidationProvider
{
public function rules(): array
{
return ['title' => ['required',],];
}
}

$validationProvider = ValidationProvider::make([
'author' => [
AuthorValidationProvider::class,
new ArrayValidationProvider('books', new BookValidationProvider()),
],
]);
$validationProvider->rules();
// [
// 'author.name' => ['required'],
// 'author.books.*.title' => ['required'],
// ]
```

---

- [Simple Example](#simple-example)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
Expand Down

0 comments on commit 341f503

Please sign in to comment.