This release introduces a first-party way to cast directly to a DTO of your choice.
Firstly, add the "CastsToDto" trait to your request. After that, you need to add the "castToDto" method on the request. This should return your DTO with the data populated inside of it.
public function castToDto(SaloonResponse $response): object
{
return User::fromSaloon($response);
}
After your request has been sent, you can use the dto
method on the response to retrieve your DTO.
$response = UserRequest::make()->send();
$dto = $response->dto(); // Data\User
What's Changed
- Added new 'CastsToDto' plugin by @Sammyjo20 in #40
Full Changelog: v0.8.0...v0.8.1