PHP code example of juststeveking / laravel-data-object-tools
1. Go to this page and download the library: Download juststeveking/laravel-data-object-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/ */
juststeveking / laravel-data-object-tools example snippets
class StoreController
{
public function __construct(
private readonly HydratorContract $hydrator,
) {}
public function __invoke(StoreRequest $request)
{
$model = Model::query()->create(
attributes: $this->hydrator->fill(
class: ModelObject::class,
parameters: $request->validated(),
)->toArray(),
);
}
}
class StoreController
{
public function __invoke(StoreRequest $request)
{
$model = Model::query()->create(
attributes: Hydrator::fill(
class: ModelObject::class,
parameters: $request->validated(),
)->toArray(),
);
}
}
bash
php artisan make:dto MyDto