Generate modern, type-safe Data Transfer Objects (DTOs) in Laravel from clean YAML definitions β with automatic validation, nested support, and fluent collection handling.
Laravel Arc is a powerful Laravel package that simplifies Data Transfer Object (DTO) management through YAML-driven generation. Define your DTOs in simple YAML files and let Laravel Arc generate type-safe, validated PHP classes with automatic property access and comprehensive collection support.
Think of it as Laravel API Resources, but with stronger typing, automatic validation, and generated from YAML definitions.
- ποΈ YAML-Driven Generation - Define DTOs in clean, readable YAML
- π Type Safety - Full PHP 8.3+ type enforcement with readonly properties
- β Automatic Validation - Generate Laravel validation rules from field definitions
- οΏ½ ModelSchema Integration - 65+ advanced field types (geometric, JSON, enhanced validation)
- οΏ½π Field Transformers - Built-in data transformation (trim, slugify, normalize, etc.)
- π Export Formats - Convert to JSON, XML, CSV, YAML, and more
- π― Behavioral Traits - Timestamps, UUIDs, soft deletes, and tagging
- π Modern PHP - Leverages PHP 8.3+ features and best practices
Laravel Arc integrates with grazulex/laravel-modelschema to provide 65+ advanced field types:
# Traditional Arc types
fields:
name:
type: string
age:
type: integer
# Advanced ModelSchema types
fields:
coordinates:
type: point # Geographic point
boundary:
type: polygon # Geographic polygon
metadata:
type: json # JSON with validation
tags:
type: set # Set collection
email:
type: email # Enhanced email validation
settings:
type: jsonb # PostgreSQL JSONB
Supported Advanced Types:
- π Geometric:
point
,polygon
,geometry
,linestring
- π JSON:
json
,jsonb
,set
,array
- π§ Enhanced String:
email
,uuid
,url
,slug
,phone
- π’ Numeric Variations:
bigint
,tinyint
,decimal
,money
- π
Date/Time:
datetime
,timestamp
,date
,time
β‘οΈ Visit the Wiki for complete documentation, examples, and guides
The wiki contains:
- Installation & Setup
- Your First DTO
- Field Types
- Field Transformers
- Artisan Commands
- Complete Examples
composer require grazulex/laravel-arc
php artisan vendor:publish --provider="Grazulex\LaravelArc\LaravelArcServiceProvider"
- Create a DTO definition:
php artisan dto:definition-init UserDTO --model=App\\Models\\User --table=users
- Generate the DTO class:
php artisan dto:generate user.yaml
- Use your DTO:
$userData = ['name' => 'John Doe', 'email' => 'john@example.com'];
$userDto = UserDTO::fromArray($userData);
echo $userDto->name; // 'John Doe'
echo $userDto->toJson(); // JSON representation
When using validation rules that contain commas (like exists:table,column
), wrap them in quotes:
# β Wrong - gets split into separate rules
rules: [required, exists:users,id]
# β
Correct - stays as one rule
rules: [required, "exists:users,id"]
This applies to rules like: "exists:table,column"
, "unique:table,column"
, "in:value1,value2,value3"
, etc.
- π Complete Documentation - Full guides and API reference
- π Installation & Setup - Installation and first steps
- π‘ Complete Examples - Real-world usage examples
- π§ Behavioral Traits - Advanced features and traits
- PHP: ^8.3
- Laravel: ^12.19
- Carbon: ^3.10
composer test
We welcome contributions! Please see our Contributing Guide for details.
Please review our Security Policy for reporting vulnerabilities.
Laravel Arc is open-sourced software licensed under the MIT license.
Made with β€οΈ by Jean-Marc Strauven