coderscantina/laravel-transform-requests

A form request wrapper for applying transformations to incoming requests
8,148
Install
composer require coderscantina/laravel-transform-requests
Latest Version:v1.0.1
PHP:^8.0
License:MIT
Last Updated:Oct 24, 2024
Links: GitHub  ·  Packagist
Maintainer: badmike

Laravel Transform Request from Coder's Cantina

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

Related Packages

gabrieloliverio/laravel5-generators

Database metadata-based generators for Laravel 5

1
erirk/paypalpayment

laravel-paypalpayment is simple package help you process direct credit card paym...

0
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444