ge-tracker / spatie-generators
Artisan make generators for Spatie Actions and DTO
Installs: 2 052
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- illuminate/console: ^8.0|^9.0
- illuminate/support: ^8.0|^9.0
- spatie/data-transfer-object: ^3.0
- spatie/laravel-queueable-action: ^2.5
README
This package adds artisan:make
commands to generate an Action or Data Transfer Object.
Installation
- Install Spatie Generators
composer require ge-tracker/spatie-generators
- The service provider will be automatically loaded - installation complete!
Usage
Generating an Action
Running the following command will generate a TestAction
into the app/Actions
directory.
php artisan make:action TestAction
The -d
or -m
parameters can be optionally specified to generate the action into a Domain
or Modules
directory. If both parameters are supplied, domain will take precedence.
The following command will generate a TestAction
into the app/Domain/Example/Actions
directory.
php artisan make:action TestAction -d Example
Generating a DTO
A DTO can be generated in the same way as an action, and supports both the -d
and -m
parameters.
php artisan make:dto TestData
A DTO can also be a collection of DTOs, which is handled automatically by Spatie's package. Spatie Generators will attempt to automatically decide the name of your target data object, to avoid any manual configuration.
php artisan make:dto TestDataCollection --collection
Will generate the following class:
<?php namespace App\DTO; use Spatie\DataTransferObject\DataTransferObjectCollection; class TestDataCollection extends DataTransferObjectCollection { public function current(): TestData { return parent::current(); } }