承接 masterskill/dto 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱: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
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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