Skip to content

Latest commit

 

History

History
72 lines (47 loc) · 1.96 KB

README.md

File metadata and controls

72 lines (47 loc) · 1.96 KB

Spatie Generators

This package adds artisan:make commands to generate an Action or Data Transfer Object.

Installation

  1. Install Spatie Generators
composer require ge-tracker/spatie-generators
  1. 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();
    }
}

Contributors