1. Go to this page and download the library: Download bpartner/dto library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bpartner / dto example snippets
class DemoDto extends DtoAbstract
{
//Optional
protected const CLASS_FORM_REQUEST = UpdateUserFormRequest::class;
/**
* DTO fields
*/
public string $name;
public Carbon $date;
public DtoOtherObject $otherObject;
/** @var collection<\App\Dto\DtoOtherObject> */
public Collection $objectsCollection;
/** @var array<\App\Dto\DtoOtherObject> */
public array $objectsArray;
/** @var collection<\App\Dto\DtoOtherObject> */
public array $objectsArrayOfCollection;
}
//In any place of your code
$data = request()->all(); //array data
$dto = Dto::build(DemoDto::class, $data);
/**
* In controller
*
* Create FormRequest and assign to CLASS_FORM_REQUEST const in DTO
*
*/
public function store(DemoDto $dto)
{
//Use $dto made from UpdateUserFormRequest
}