PHP code example of divineomega / uxdm-spatie-data-transfer-object

1. Go to this page and download the library: Download divineomega/uxdm-spatie-data-transfer-object 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/ */

    

divineomega / uxdm-spatie-data-transfer-object example snippets


$users = new UserDTOCollection([
    new UserDTO([
        'id' => 1,
        'name' => 'Picard`',
        'email' => '[email protected]',
    ]),
    new UserDTO([
        'id' => 2,
        'name' => 'Janeway',
        'email' => '[email protected]',
    ])
]);

$spatieDataTransferObjectSource = new SpatieDataTransferObjectSource($users);

$migrator = new Migrator;
$migrator->setSource($spatieDataTransferObjectSource);

$users = new UserDTOCollection();
$spatieDataTransferObjectDestination = new SpatieDataTransferObjectDestination($users, UserDTO::class);

$migrator = new Migrator;
$migrator->setDestination($spatieDataTransferObjectDestination);

$migrator = new Migrator;
$migrator->addDestination($spatieDataTransferObjectDestination, ['field1', 'field2']);
$migrator->addDestination($otherDestination, ['field3', 'field2']);