PHP code example of isakzhanov-r / laravel-dto

1. Go to this page and download the library: Download isakzhanov-r/laravel-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/ */

    

isakzhanov-r / laravel-dto example snippets


use IsakzhanovR\DataTransferObject\DataTransferObject;
use IsakzhanovR\ValueObject\Email  // example

class UserData extends DataTransferObject 
{
    public $id;
    
    public string $name;
    
    /**
    * @var \IsakzhanovR\ValueObject\Email
    * @throws \App\Exceptions\EmailDataExeption
    */
    public Email $email;
    
    /**
    * @var IsakzhanovR\DataTransferObject\FiledDTO[] - example
    */
    public array $fields;
}


$dto = new UserData(['id' => 1,'name' => 'Example',' email' => '[email protected]']);

$array = ['id' => 1,'name' => 'Example',' email' => '[email protected]'];

$dto = UserData::fromArray($array);

$object = new stdClass();
$object->id = 1;
$object->name = 'Example';
$object->email = '[email protected]';

$dto = UserData::fromObject($object);

$dto = UserData::fromRequest($request);

$dto = UserData::fromJson(json_encode($array));



$dto->get()



$dto->toArray()