masterskill/dto
Composer 安装命令:
composer require masterskill/dto
包简介
This package is intended for the adoption of the DTO schema in Laravel, which is a system for controlling incoming and outgoing data, in collaboration with the Laravel formRequest, or the Eloquent model
README 文档
README
The project
This package is intended for the adoption of the DTO schema in Laravel, which is a system for controlling incoming and outgoing data, in collaboration with the Laravel formRequest, or the Eloquent model.
Installation
To install the project, you should install it from composer :
composer require masterskill/dto
After that, you should publish the config file.
The DTO class
The Dto class has a different properties to handle. Exemple of the DTO :
<?php namespace App\Http\Dto; class UserDto { public function __construct( public readonly string $name, public readonly string $email ) {} }
Or, eventially, the DTO can implements the IRequestBasedDto or IModelBasedDto interfaces to add some functionnality.
<?php namespace App\Http\Dto; use Masterskill\Dto\Interfaces\IRequestBasedDto; use Masterskill\Dto\Interfaces\IModelBasedDto; use Illuminate\Http\Request; use App\Models\User; class UserDto implements IRequestBased, IModelBasedDto { public function __construct( public readonly string $name, public readonly string $email ) {} public static function fromRequest(Request $request) { return new static("John Doe" , "john.doe@example.com") } public static function fromModel(User $user) { return new static($user->name , $user->email) } }
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-07-03