-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from WendellAdriel/fix-dto-transform
Fix issue when transforming DTOs with nested Collections or Models
- Loading branch information
Showing
3 changed files
with
140 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WendellAdriel\ValidatedDTO\Tests\Datasets; | ||
|
||
use Illuminate\Support\Collection; | ||
use WendellAdriel\ValidatedDTO\Casting\CollectionCast; | ||
use WendellAdriel\ValidatedDTO\Casting\DTOCast; | ||
use WendellAdriel\ValidatedDTO\ValidatedDTO; | ||
|
||
class UserNestedCollectionDTO extends ValidatedDTO | ||
{ | ||
public Collection $names; | ||
|
||
public string $email; | ||
|
||
protected function rules(): array | ||
{ | ||
return [ | ||
'names' => ['required', 'array'], | ||
'email' => ['required', 'email'], | ||
]; | ||
} | ||
|
||
protected function defaults(): array | ||
{ | ||
return []; | ||
} | ||
|
||
protected function casts(): array | ||
{ | ||
return [ | ||
'names' => new CollectionCast(new DTOCast(NameDTO::class)), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters