Download the PHP package qbejs/laravel-dto-mapper without Composer
On this page you can find all versions of the php package qbejs/laravel-dto-mapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download qbejs/laravel-dto-mapper
More information about qbejs/laravel-dto-mapper
Files in qbejs/laravel-dto-mapper
Package laravel-dto-mapper
Short Description Automatic DTO mapping for Laravel using PHP 8 Attributes
License MIT
Informations about the package laravel-dto-mapper
๐ฆ Laravel DTO Mapper
Automatic HTTP request mapping to DTO classes in Laravel using PHP 8 Attributes. A simple, clean, and type-safe way to handle validation and data mapping in your controllers.
โจ Features
- ๐ฏ PHP 8 Attributes - Clean and modern syntax
- โ Automatic Validation - Uses Laravel's built-in Validator
- ๐ Type Safety - Full support for typed properties
- ๐ File Handling - Automatic
UploadedFilemapping - ๐ Arrays & Bulk Operations - Complete array mapping support
- ๐ Zero Configuration - Works out-of-the-box with Package Discovery
- ๐งช Easy Testing - DTOs are simple PHP classes
๐ Requirements
- PHP 8.1 or higher
- Laravel 9.x, 10.x, 11.x, or 12.x
๐ง Installation
The Service Provider will be automatically registered via Laravel Package Discovery.
๐ Quick Start
1. Create a DTO
2. Use in Controller
3. Done! ๐
Your endpoint now:
- โ Automatically validates data
- โ Returns clear validation errors
- โ Maps data to type-safe DTO
- โ Is easy to test
๐ Documentation
Available Attributes
#[MapRequestPayload] - Request Body
Maps data from request body (POST/PUT/PATCH) to DTO.
Options:
validate: bool- Enable validation (default: true)stopOnFirstFailure: bool- Stop at first validation error (default: false)
Examples:
#[MapQueryString] - URL Parameters
Maps query string parameters (GET) to DTO.
File Handling
Single File Upload
Multiple File Uploads
Usage in Controller
Bulk Operations
Error Handling
When validation fails, a 422 response is returned:
๐งช Testing
๐ก Best Practices
DTO Organization
Structure your DTOs by feature/entity:
Naming Conventions
- Create:
Create{Entity}DTO- for creating new resources - Update:
Update{Entity}DTO- for updating existing resources - Filter/Search:
{Entity}FilterDTO- for search parameters - Bulk:
Bulk{Action}{Entity}DTO- for bulk operations
Always Use Type Hints
DTOs Should NOT Have Constructors
๐ Common Issues
Property must not be accessed before initialization
Problem: DTO property is not being populated.
Solution: Make sure:
- Property names match request parameter names (case-sensitive!)
- You're sending the parameter in the request
- For GET requests, use
#[MapQueryString] - For POST/PUT/PATCH, use
#[MapRequestPayload]
Unresolvable dependency
Problem: DTO has a constructor with parameters.
Solution: Remove the constructor. DTOs should only have public properties.
๐ค Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
๐ Changelog
See CHANGELOG.md for recent changes.
๐ License
The MIT License (MIT). Please see License File for more information.
๐ Credits
- Jakub Skowron
- All Contributors
๐ฌ Support
- ๐ซ Create an issue
- ๐ฌ Discussions
โญ Show Your Support
If this package helped you, please consider giving it a โญ on GitHub!
Made with โค๏ธ for the Laravel community
All versions of laravel-dto-mapper with dependencies
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/validation Version ^9.0|^10.0|^11.0|^12.0
illuminate/http Version ^9.0|^10.0|^11.0|^12.0
illuminate/routing Version ^9.0|^10.0|^11.0|^12.0