holiq / action-data
Laravel Package for generate Actions and DTOs on your projects
v1.0.0
2024-08-21 08:21 UTC
Requires
- php: ^8.2
- cuyz/valinor: ^1.0
- illuminate/console: ^11.0
- illuminate/container: ^11.0
- illuminate/filesystem: ^11.0
- illuminate/support: ^11.0
- spatie/php-cloneable: ^1.0
Requires (Dev)
- laravel/pint: ^v1.0
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/phpstan: ^1.0
README
Installation
composer require holiq/action-data
Commands
Actions
php artisan make:action StorePostAction
DataTransferObjects
php artisan make:dto StorePostAction
Example used
// DTO namespace App\DataTransferObjects; use Holiq\ActionData\Foundation\DataTransferObject; readonly class CategoryData extends DataTransferObject { public function __construct( public string $name, ) {} } // Action namespace App\Actions\Category; use App\DataTransferObjects\CategoryData; use App\Models\Category; use Holiq\ActionData\Foundation\Action; readonly class StoreCategoryAction extends Action { public function execute(CategoryData $data): void { Category::query()->create($data->toArray()); } } // Controller namespace App\Http\Controllers\Category; use App\Actions\Category\StoreCategoryAction; use App\DataTransferObjects\CategoryData; use App\Http\Controllers\Controller; use App\Http\Requests\Category\StoreCategoryRequest; use CuyZ\Valinor\Mapper\MappingError; use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Redirect; class StoreCategoryController extends Controller { /** * @throws MappingError */ public function __invoke(StoreCategoryRequest $storeCategoryRequest): RedirectResponse { StoreCategoryAction::resolve()->execute( data: CategoryData::resolve(data: $storeCategoryRequest->validated()) ); return Redirect::back(); } }