Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Dec 6, 2021
1 parent 590c916 commit b128615
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/as-a-data-transfer-object/request-to-data-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,35 @@ class SongData extends Data

If the method returns `false`, then an `AuthorizationException` is thrown.

## Validating a collection of data objects:

Let's say we want to create a data object like this from a request:

```php
class AlbumData extends Data
{
public function __construct(
public string $title,
/** @var SongData[] */
public DataCollection $songs,
) {
}
}
```

Since the `SongData` has its own validation rules, the package will automatically apply them when resolving validation rules for this object.

In this case the validation rules for `AlbumData` would look like this:

```php
[
'title' => ['required', 'string'],
'songs' => ['required', 'array'],
'songs.*.title' => ['required', 'string'],
'songs.*.artist' => ['required', 'string'],
]
```

## Validating a data object without request

It is also possible to validate values for a data object without using a request:
Expand Down

0 comments on commit b128615

Please sign in to comment.