Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ge-tracker/spatie-generators

Artisan 'make' generator commands for Spatie Actions and DTO
https://github.com/ge-tracker/spatie-generators

dto spatie

Last synced: about 2 months ago
JSON representation

Artisan 'make' generator commands for Spatie Actions and DTO

Awesome Lists containing this project

README

        

# Spatie Generators

This package adds `artisan:make` commands to generate an [Action](https://packagist.org/packages/spatie/laravel-queueable-action) or [Data Transfer Object](https://packagist.org/packages/spatie/data-transfer-object).

* [Refactoring to actions](https://freek.dev/1371-refactoring-to-actions)
* [Laravel queueable actions](https://stitcher.io/blog/laravel-queueable-actions)
* [Organise by domain](https://stitcher.io/blog/organise-by-domain)

## Installation

1. Install Spatie Generators

```bash
composer require ge-tracker/spatie-generators
```

2. 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.

```bash
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.

```bash
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.

```bash
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.

```bash
php artisan make:dto TestDataCollection --collection
```

Will generate the following class:

```php