grazulex / laravel-arc
A Laravel package for elegant and modern Data Transfer Objects (DTOs) management with automatic validation and direct property access
Fund package maintenance!
Grazulex
Buy Me A Coffee
paypal.me/strauven
Requires
- php: ^8.3
- grazulex/laravel-modelschema: ^1.1
- illuminate/support: ^12.19
- nesbot/carbon: ^3.10
Requires (Dev)
- doctrine/dbal: ^4.2
- larastan/larastan: ^3.4
- laravel/pint: ^1.22
- orchestra/testbench: ^10.0
- pestphp/pest: ^3.8
- pestphp/pest-plugin-laravel: ^3.2
- rector/rector: ^2.0
Suggests
- doctrine/dbal: Required for command `php artisan arc:generate-dto` to generate migrations from DTOs
README
Generate modern, type-safe Data Transfer Objects (DTOs) in Laravel from clean YAML definitions โ with automatic validation, nested support, and fluent collection handling.
Overview
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.
๐ฏ Key Features
- ๐๏ธ 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
๐ง Advanced Field Types (ModelSchema Integration)
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
๐ Complete Documentation
โก๏ธ 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
๐ฆ Quick Installation
composer require grazulex/laravel-arc
php artisan vendor:publish --provider="Grazulex\LaravelArc\LaravelArcServiceProvider"
๐ Quick Start
- 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
โ ๏ธ Important Notes
YAML Validation Rules with Commas
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.
๐ Learn More
- ๐ 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
๐ง Requirements
- PHP: ^8.3
- Laravel: ^12.19
- Carbon: ^3.10
๐งช Testing
composer test
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
๐ Security
Please review our Security Policy for reporting vulnerabilities.
๐ License
Laravel Arc is open-sourced software licensed under the MIT license.
Made with โค๏ธ by Jean-Marc Strauven