tsarturi / simpledto
为 Laravel 应用程序提供的简单数据传输对象(DTO)及 FormRequest 验证
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.此库基于 https://github.com/WendellAdriel/laravel-validated-dto 开发。
特性 | 安装 | 配置 | 生成 DTO | 生成 FormRequest
特性
特性
- 允许轻松快速地创建 DTO。
- 易于集成到现有项目中。
- 与验证请求相同的方式验证数据。
- 使用 FormRequest 进行验证和授权。
- 自定义验证消息。
- 轻松数据转换。
- 定义默认值。
安装
composer require tsarturi/simpledto
配置
发布配置文件
php artisan vendor:publish --provider="Tsarturi\SimpleDTO\Providers\SimpleDTOServiceProvider" --tag=config
生成 DTO
您可以使用 make:simpledto
命令创建 DTO
php artisan make:simpledto UserDTO
它将在 App\DTOs 文件夹中创建一个 UserDTO 类。
生成 FormRequest
您可以使用 make:simpledtoformrequest
命令创建 FormRequest 类
php artisan make:simpledtoformrequest UserStoreRequest
它将在表单请求的文件夹中创建一个 UserStoreRequest。
使用 DTO
<?php $dto = new UserDTO( [ 'name' => 'name', 'email' => 'email@email.com']);
使用 DTO 与 FormRequest 一起使用
<?php $dto = new UserDTO( [ 'name' => 'name', 'email' => 'email@email.com'], UserStoreRequest::class);