-
I am having trouble getting any (PHP 8) attributes to work. E.g. class UserData extends Data
{
public function __construct(
#[Max(5)]
public string $name,
#[WithCast(DateTimeInterfaceCast::class, format: 'Y-m-d')]
public ?CarbonImmutable $date,
#[MapInputName('createdAt')]
public CarbonImmutable $created_at,
) {
}
}
$user = [
'name' => 'John Doe',
'date' => '1972-11-05',
'createdAt' => now()->toAtomString(), // in DTO: created_at
];
$dto = App\Data\UserData::from($user); gives error for
So, the attributes (the cast, but also validation and mapinputname) are ignored? When adding
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
From another discussion (#357) I understand I should be using More importantly:
I can manually overwrite the rules which works fine (for the validation):
But it will still not recognise the |
Beta Was this translation helpful? Give feedback.
-
It was not clear from the documentation that Attributes are classes that need to imported...
|
Beta Was this translation helpful? Give feedback.
It was not clear from the documentation that Attributes are classes that need to imported...