承接 coderscantina/laravel-transform-requests 相关项目开发

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

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

coderscantina/laravel-transform-requests

最新稳定版本:v1.0.1

Composer 安装命令:

composer require coderscantina/laravel-transform-requests

包简介

A form request wrapper for applying transformations to incoming requests

README 文档

README

A form request wrapper for applying transformations to incoming requests

Features

  • Use TransformRequest to specify an array of key replacements
  • Use ApiRequest to transform all input from camelCase to snake_case

Getting started

  • Install this package

Install

Require this package with composer:

$ composer require coderscantina/laravel-transform-requests

Usage

Define a new ApiRequest:

<?php namespace App;
 
use Neon\Request\ApiRequest;
 
class TestApiRequest extends ApiRequest
{

}

Define a new TransformRequest:

  • Override the $transform field to define your transformations
  • To further customize the transformation override getTransform
<?php namespace App;
 
use Neon\Request\TransformRequest;
 
class TestTransformRequest extends TransformRequest
{
    protected $transform = [
        'foo_bar' => 'fooBar',
    ];

}

In your application, use the request as you would any other request:

curl -X POST -d '{"fooBar": "baz"}' https://localhost/
<?php

class TestController extends \Illuminate\Routing\Controller
{
    public function a(TestTransformRequest $request)
    {
        $request->get('foo_bar'); // 'baz'
        $request->all(); // -> ['foo_bar' => 'baz']
    }
    
    public function b(TestApiRequest $request)
    {
        $request->get('foo_bar'); // 'baz'
        $request->all(); // -> ['foo_bar' => 'baz']
    }
}

Testing

$ composer test

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-22