承接 laralgato/request-object 相关项目开发

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

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

laralgato/request-object

最新稳定版本:1.1.0

Composer 安装命令:

composer require laralgato/request-object

包简介

Simple way to convert your request data to an object.

README 文档

README

Latest Stable Version License

Simple way to convert your request data to an object.

Installation

Install via Composer:

composer require laralgato/request-object

Usage

After installing the package, you can simply add a trait and an attribute to your Request. The Attribute accepts the object that you want as a result of the toObject method.

use Laragato\RequestObject\Attributes\FormObject;
use Laragato\RequestObject\Traits\useObjectRequest;

#[FormObject(MyObject::class)]
class TestRequest extends FormRequest
{
    use useObjectRequest;
    ...
}

Creating the object with constructor :

In your controller you can simply use:

class TestController extends Controller
{
    public function __invoke(TestRequest $request)
    {
        $request->toObject();
    }
}

This line will perform the validation and return the object giving in the request. This is perfect for creating DTOs.

Creating Models object

If you want the result to be a Model or an object that requires the properties to be set one by one, you can use the toModel method:

class TestController extends Controller
{
    public function __invoke(TestRequest $request)
    {
        $request->toModel();
    }
}

This way you can simply call ->save() on your model

$model = $request->toModel();
$model->save();

In case you want to update the model with ->save(), you can add update: true to the Attribute. That will return copy of the model passed in the request with updated properties.

#[FormObject(MyObject::class, update: true)]

Then simply do

$model = $request->toModel();
$model->save();

To update the model.

Enjoy :)

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固