tsarturi / simpledto
Simple Data Transfer Objects with FormRequest Validation for Laravel applications
v1.0.5
2023-05-07 23:09 UTC
Requires
- php: ^8.0
- illuminate/console: ^9.0|^10.0
- illuminate/database: ^9.0|^10.0
- illuminate/http: ^9.0|^10.0
- illuminate/support: ^9.0|^10.0
- illuminate/validation: ^9.0|^10.0
Requires (Dev)
- laravel/pint: ~1.5.0
- orchestra/testbench: ^6.0|^7.20|^8.0
- pestphp/pest: v1.22.6
- pestphp/pest-plugin-faker: ^1.0.0
README
SimpleDTO
Simple Data Transfer Objects with FormRequest Validation for Laravel applications.This library was based on https://github.com/WendellAdriel/laravel-validated-dto .
Features | Installation | Configuration | Generating DTOs | Generating FormRequest
Features
Features:
- Allows the creation of DTO's easily and quickly.
- Easy integration into your existing projects.
- Validation of the data in the same way that it validates the Request.
- Use FormRequest for validation and authorization.
- Custom validation messages.
- Easy data conversion.
- Definition of default values.
Installation
composer require tsarturi/simpledto
Configuration
Publish the config file:
php artisan vendor:publish --provider="Tsarturi\SimpleDTO\Providers\SimpleDTOServiceProvider" --tag=config
Generating DTOs
You can create DTOs using the make:simpledto
command:
php artisan make:simpledto UserDTO
It's create an UserDTO class into App\DTOs folder.
Generating FormRequest
You can create FormRequest class using the make:simpledtoformrequest
command:
php artisan make:simpledtoformrequest UserStoreRequest
It's create an UserStoreRequest into Form Request's folder
Using DTO's
<?php $dto = new UserDTO( [ 'name' => 'name', 'email' => 'email@email.com']);
Using DTO's with FormRequest
<?php $dto = new UserDTO( [ 'name' => 'name', 'email' => 'email@email.com'], UserStoreRequest::class);