✅
Laravel Validated DTO
View on GitHub
  • ✅Validated DTO for Laravel
  • 🚀Getting Started
    • Installation
    • Configuration
    • Upgrade Guide
    • Changelog
  • 😎The Basics
    • Generating DTOs
    • Defining DTO Properties
    • Defining Validation Rules
    • Creating DTO Instances
    • Accessing DTO Data
    • Defining Default Values
    • Transforming DTO Data
    • Mapping DTO properties
    • Simple DTOs
    • Resource DTOs
    • Wireable DTOs
    • Lazy Validation
    • Generating TypeScript Definitions
  • 🎨Customize
    • Custom Error Messages and Attributes
    • Custom Exceptions
  • 🧪Type Casting
    • Introduction
    • Available Types
    • Create Your Own Type Cast
    • Casting Eloquent Model properties to DTOs
Powered by GitBook
On this page

Was this helpful?

  1. The Basics

Generating DTOs

You can create DTOs using the make:dto command:

php artisan make:dto UserDTO

The DTOs are going to be created inside app/DTOs by default. You can customize the path by updating the namespace property in the config/dto.php file:

/*
|--------------------------------------------------------------------------
| NAMESPACE
|--------------------------------------------------------------------------
|
| The namespace where your DTOs will be created.
|
*/

'namespace' => 'App\\DTOs',

Compared to v2, the generated DTO from v3 is more simple and only contains the most used methods:

  • rules() (For Validated DTOs only)

  • defaults()

  • casts()

If you want to customize further your DTO add the missing methods when needed.

  • messages()

  • attributes()

  • mapData()

  • mapToTransform()

Customizing DTO Stubs

You can publish the DTO stubs to customize them to your needs with the dto:stubs command. This will create the stubs in a stubs folder at the root of the project.

PreviousChangelogNextDefining DTO Properties

Last updated 1 year ago

Was this helpful?

😎