ge-tracker/spatie-generators

This package is abandoned and no longer maintained. No replacement package was suggested.

Artisan make generators for Spatie Actions and DTO

v2.0.3 2022-02-09 12:29 UTC

This package is auto-updated.

Last update: 2023-03-06 12:09:36 UTC


README

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