定制 phpsa/laravel-case-remapping 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

phpsa/laravel-case-remapping

Composer 安装命令:

composer require phpsa/laravel-case-remapping

包简介

Methods to allow the mapping of cases to snake / camel for input / output

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

Installation

You can install the package via composer:

composer require phpsa/laravel-case-remapping

Usage - Middlware for incomming requests

Add as a middleware: Phpsa\LaravelCaseRemapping\Http\Middleware\SnakeCaseInputs to your route eg:

Route::post('xxx',[...])->withMiddleware(\Phpsa\LaravelCaseRemapping\Http\Middleware\SnakeCaseInputs::class)

in your controllers constructor:

public function __construct()
{
    $this->middleware(\Phpsa\LaravelCaseRemapping\Http\Middleware\SnakeCaseInputs::class);
}

Or globally via the app/Http.Kernal.php file

protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' => [
            'throttle:api',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \Phpsa\LaravelCaseRemapping\Http\Middleware\SnakeCaseInputs::class
        ],
    ];

Usage - Response wrapping for your Transformers / Response objects

add the following trait to your resource: \Phpsa\LaravelCaseRemapping\Http\Resources\WithAcceptedCase

then in your toArray method change to per example

public function toArray($request){
    $data = parent::toArray($request);

    ... // any other modifications

    return $this->toAcceptCase($request, $data);
}

based on the header value for X-Accept-Case-Type passed to the request it will reaturn one of the following camel, kebab, snake

Usage - Collection methods

This packages includes 3 collecion macros:

  • snakeKeys - will convert all array keys to snake case
  • camelKeys - will convert all array keys to camel case
  • kebabKeys - will convert all array keys to kebab case

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固