This package add castTo
and HydrateTo
methods to the request object for facilitate filling Data Transfer Objects.
composer require mvaliolahi/request-hydrator
$postDTOOne = request()->castTo(PostDTO::class);
$postDTOTwo = request()->hydrateTo(PostDTO::class);
$postDTO = request()->castTo(PostDTO::class, [
'title' => ucfirst(request()->title)
]);