Links

Accessing DTO Data

After you create your DTO instance, you can access any properties like an object:
$dto = new UserDTO([
'name' => 'John Doe',
'email' => '[email protected]',
'password' => 's3CreT!@1a2B'
]);
$dto->name; // 'John Doe'
$dto->email; // '[email protected]'
$dto->password; // 's3CreT!@1a2B'
If you pass properties that are not listed in the rules method of your DTO, this data will be ignored and won't be available in your DTO:
$dto = new UserDTO([
'name' => 'John Doe',
'email' => '[email protected]',
'password' => 's3CreT!@1a2B',
'username' => 'john_doe',
]);
$dto->username; // THIS WON'T BE AVAILABLE IN YOUR DTO