PHP code example of r4nkt / laravel-dto-action

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

    

r4nkt / laravel-dto-action example snippets


$data = [
    'email' => '[email protected]',
    'list' => $emailList,
    'attributes' => $attributes,
    'confirm' => false,
    'send_welcome_mail' => false,
];

// create the DTO for the CreateSubscriber action and then execute the action
CreateSubscriber::dto($data)->execute();

UpdateLeaderboard::dto($data)->execute();

$data = [
    'player' => $peter,
    'score' = $petersScore,
];

$updateLeaderboardDto = UpdateLeaderboard::dto($data);

$updateLeaderboardDto->execute();

$updateLeaderboardDto->player = $paul;
$updateLeaderboardDto->score = $paulsScore;
$updateLeaderboardDto->execute();

UpdateLeaderboard::dtoFromRequest($request)->execute();
 php
use R4nkt\LaravelDtoAction\Action;

class CreateSubscriber extends Action
{
    public function __invoke(CreateSubscriberDto $dto)
    {
        // code to perform action, using $dto as needed...
    }

    // supporting methods, if needed...
}