PHP code example of mohamad-zatar / laravel-dto-tools

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

    

mohamad-zatar / laravel-dto-tools example snippets


class InventoryController
{
    public function __construct(
        private readonly HydratorContract $hydrator,
    ) {}
    
    public function __invoke(InventoryRequest $request)
    {
        $model = Model::query()->create(
            attributes: $this->hydrator->fill(
                class: ModelObject::class,
                parameters: $request->validated(),
            )->toArray(),
        );
    }
}

class InventoryController
{
    public function __invoke(InventoryRequest $request)
    {
        $model = Model::query()->create(
            attributes: Hydrator::fill(
                class: ModelObject::class,
                parameters: $request->validated(),
            )->toArray(),
        );
    }
}
bash
php artisan make:dto MyDto