PHPackages                             julio-cavallari/laravel-dto - 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. julio-cavallari/laravel-dto

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

julio-cavallari/laravel-dto
===========================

Laravel package to automatically generate DTOs from Form Request classes

v1.0.4(11mo ago)4744MITPHPPHP ^8.2|^8.3|^8.4

Since Jul 12Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/julio-cavallari/laravel-dto)[ Packagist](https://packagist.org/packages/julio-cavallari/laravel-dto)[ Docs](https://github.com/julio-cavallari/laravel-dto)[ RSS](/packages/julio-cavallari-laravel-dto/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (10)Versions (7)Used By (0)

Laravel DTO Generator
=====================

[](#laravel-dto-generator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ca34533a22422b9e996253f39f40ab55e77407cf78e025b493a2594405819403/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a756c696f2d636176616c6c6172692f6c61726176656c2d64746f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/julio-cavallari/laravel-dto)[![Total Downloads](https://camo.githubusercontent.com/900622912970f27feef92c08c2ba18b53a290bcb18ca40a9ba0c65bd723e2b2f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a756c696f2d636176616c6c6172692f6c61726176656c2d64746f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/julio-cavallari/laravel-dto)

A Laravel package that automatically generates Data Transfer Objects (DTOs) from Form Request classes, keeping them in sync with your validation rules.

Features
--------

[](#features)

- 🚀 **Automatic Generation**: Generate DTOs from existing Form Request classes
- 🔄 **Stay in Sync**: Keep DTOs updated with Form Request changes
- 🛡️ **Type Safe**: Generate strongly typed DTOs with proper type hints
- 🎯 **Immutable**: Generate readonly DTOs for better data integrity
- 🏷️ **Smart Enums**: Automatically generate PHP 8.1+ enums from "in" validation rules
- ⚡ **Fast**: Efficient parsing and generation
- 🔧 **Configurable**: Customize namespaces, paths, and generation options

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

[](#installation)

You can install the package via composer:

```
composer require julio-cavallari/laravel-dto
```

Optionally, you can publish the config file:

```
php artisan vendor:publish --tag=laravel-dto-config
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Generate DTOs for all Form Requests:

```
php artisan dto:generate
```

Generate DTO for a specific Form Request:

```
php artisan dto:generate CreateArticleRequest
```

### Checking DTO Status

[](#checking-dto-status)

Check which Form Requests have corresponding DTOs:

```
# Check all Form Requests
php artisan dto:check

# Show only Form Requests without DTOs
php artisan dto:check --missing

# Show only Form Requests with DTOs
php artisan dto:check --existing

# Show detailed information
php artisan dto:check --details
```

### Command Options

[](#command-options)

- `--force`: Force regenerate existing DTOs
- `--dry-run`: Preview changes without writing files
- `--enhance-requests`: Add toDto() method to Form Requests using trait

```
# Force regenerate all DTOs
php artisan dto:generate --force

# Preview what would be generated
php artisan dto:generate --dry-run
```

### Example

[](#example)

Given this Form Request:

```
