24 lines
546 B
PHP
24 lines
546 B
PHP
<?php
|
|
|
|
namespace App\Actions\Category;
|
|
|
|
use App\DTOs\CategoryData;
|
|
use App\Events\ModelChanged;
|
|
use App\Models\Category;
|
|
use App\Repositories\Contracts\CategoryRepositoryInterface;
|
|
|
|
class CreateCategoryAction
|
|
{
|
|
public function __construct(private CategoryRepositoryInterface $repository) {}
|
|
|
|
public function execute(CategoryData $data): Category
|
|
{
|
|
/** @var Category */
|
|
$result = $this->repository->create($data->toArray());
|
|
|
|
ModelChanged::dispatch(Category::class, 'created');
|
|
|
|
return $result;
|
|
}
|
|
}
|