kfoobar/laravel-dto

Laravel 的基本数据传输对象

v1.0.0 2022-02-17 23:02 UTC

This package is auto-updated.

Last update: 2024-09-18 04:48:52 UTC


README

Laravel 5.5+ 的基本数据传输对象

安装

您可以通过 composer 安装此包

$ composer require kfoobar/laravel-dto

基本用法

首先,创建一个扩展 KFoobar\LaravelData\Objects\DataTransferObject 的类

class PostData extends DataTransferObject
{
    public int $id;
    public string $title;
    public string $content;
}

然后,您可以使用以下方法初始化并填充您的对象

$postData = new PostData::fromArray([...]);
$postData = new PostData::fromRequest($request);
$postData = new PostData::fromModel($post);

贡献

欢迎贡献!

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件