masterskill/dto 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-07-03