PHPackages                             holiq/action-data - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. holiq/action-data

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

holiq/action-data
=================

Laravel Package for generate Actions and DTOs on your projects

v2.0.0(1mo ago)0719MITPHPPHP ^8.3

Since Aug 21Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/holiq/action-data)[ Packagist](https://packagist.org/packages/holiq/action-data)[ RSS](/packages/holiq-action-data/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (23)Versions (13)Used By (0)

Laravel Action Data
===================

[](#laravel-action-data)

[![Latest Version on Packagist](https://camo.githubusercontent.com/75e38e6fbc4824866975fbffe17489b324a7858b4acaac0f8f1e37fbba6d1e5c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f686f6c69712f616374696f6e2d646174612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/holiq/action-data)[![Total Downloads](https://camo.githubusercontent.com/2fc1e2564062becf4a8cca5e98b4c83468e9b248d1bc5dac86be90043113e6c3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f6c69712f616374696f6e2d646174612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/holiq/action-data)[![License](https://camo.githubusercontent.com/f7b8fcb6ef44d0a03d59321ca6fcf141402a02ce48536250c7e93ee75b3dbfb8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f6c69712f616374696f6e2d646174612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/holiq/action-data)

A Laravel package that provides an elegant way to generate and use Actions and Data Transfer Objects (DTOs) in your Laravel projects. This package promotes clean architecture by separating business logic into reusable Action classes and ensuring type-safe data handling with DTOs.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage](#usage)
    - [Generating Actions](#generating-actions)
    - [Generating DTOs](#generating-dtos)
    - [Working with DTOs](#working-with-dtos)
    - [Validation](#validation)
    - [Nested DTOs](#nested-dtos)
    - [Data Transformations](#data-transformations)
- [Real-world Examples](#real-world-examples)
- [API Reference](#api-reference)
- [Testing](#testing)
- [Contributing](#contributing)
- [License](#license)

Features
--------

[](#features)

- 🚀 **Simple Command Generation**: Generate Actions and DTOs with simple Artisan commands
- 🔒 **Type Safety**: Built with PHP 8.3+ readonly classes for immutable data structures
- 🏗️ **Clean Architecture**: Promotes separation of concerns and clean code practices
- 🔄 **Automatic Data Mapping**: Seamless conversion between arrays, Form Requests, and Models
- ✅ **Attribute-Based Validation**: Use PHP attributes for declarative validation rules
- 🔧 **Custom Validation**: Support for custom validation callbacks and pipelines
- 🌳 **Nested DTOs**: Automatic resolution of nested DTOs and arrays of DTOs
- 🔄 **Data Transformations**: Built-in data transformation pipeline for clean data processing
- 📁 **Customizable Paths**: Configure custom paths for Actions and DTOs
- 🧪 **Well Tested**: Comprehensive test suite ensuring reliability
- 📖 **Rich Documentation**: Extensive documentation and examples

Requirements
------------

[](#requirements)

- PHP 8.3 or higher
- Laravel 12.0 or 13.0

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require holiq/action-data
```

The package will automatically register its service provider.

Optionally, you can publish the configuration file:

```
php artisan vendor:publish --provider="Holiq\ActionData\ActionDataServiceProvider" --tag="config"
```

After publishing, you can customize the paths in `config/action-data.php`:

```
return [
    'action_path' => 'app/Actions',
    'data_path' => 'app/DataTransferObjects',
];
```

Quick Start
-----------

[](#quick-start)

1. **Generate an Action with DTO:**

    ```
    php artisan make:action CreateUserAction --with-dto=CreateUserData
    ```
2. **Define your DTO with validation:**

    ```
    readonly class CreateUserData extends DataTransferObject
    {
        public function __construct(
            #[Required, Length(min: 2, max: 50)]
            public string $name,

            #[Required, Email]
            public string $email,
        ) {}
    }
    ```
3. **Implement your Action:**

    ```
    readonly class CreateUserAction extends Action
    {
        public function execute(CreateUserData $data): User
        {
            return User::create($data->toArray());
        }
    }
    ```
4. **Use in your controller:**

    ```
    $userData = CreateUserData::resolve($request->validated())
        ->validateAttributes();

    $user = CreateUserAction::resolve()->execute($userData);
    ```

Configuration
-------------

[](#configuration)

After publishing the configuration file, you can customize the paths where Actions and DTOs are generated:

```
// config/action-data.php
return [
    'action_path' => 'app/Actions',
    'data_path' => 'app/DataTransferObjects',
];
```

Usage
-----

[](#usage)

### Generating Actions

[](#generating-actions)

Generate Actions using the Artisan command with various options:

```
# Basic action
php artisan make:action StoreUserAction

# Action in subdirectory
php artisan make:action User/StoreUserAction

# Action with auto-generated DTO
php artisan make:action StoreUserAction --with-dto=StoreUserData

# Force overwrite existing files
php artisan make:action StoreUserAction --force
```

**Basic Action structure:**

```
