yzen.dev/request-data-adapter

Adapter for converting input data from Illuminate\Http\Request
2,561 2
Install
composer require yzen.dev/request-data-adapter
Latest Version:0.0.2
PHP:^7.0
License:MIT
Last Updated:Feb 1, 2023
Links: GitHub  ·  Packagist
Maintainer: yzen.dev

RequestDataAdapter - Adapter for converting input data from Illuminate\Http\Request

This package provides easy conversion of input keys to your internal keys.

This adapter is perfect for you if for example you do not want to give your internal keys containing typos (but we know that you can’t have this😉), or vice versa, translate incorrect keys into the correct form.

:scroll: Installation

The package can be installed via composer:

composer require yzen.dev/request-data-adapter

:scroll: Usage

To use the adapter, you must connect this trait:

class CommentStoreRequest extends FormRequest
{
    use RequestDataAdapter;
    ...
}

Then you need to implement the mappingData method (PHPStorm itself will offer you add method stubs)

    /**
     * {@inheritDoc}
     */
    public function mappingData(): array
    {
        return [
            'tatle' => 'title',
            'autor' => 'author',
            'files' => [
                'file' => [
                    'document_name' => 'name'
                ],
            ],
            'additions' => [
                'date' => 'date_time',
            ],
        ];
    }

Thus, you can already work in the controller with the data set you need:

{
  "title": "Test packages",
  "author": "Taylor",
  "files": [
    {
      "file": {
        "document_name": "my_photo"
      }
    }
  ],
  "additions": {
    "date": "date_time"
  }
}

Related Packages

inpin/backend-foundation

Backend (Laravel) foundation base classes

45 0
mpyw/laravel-cached-database-stickiness

Guarantee database stickiness over the same user's consecutive requests

381,279 83
ordent/ramenplatform

This package provides a streamlines and easy way to create api based service on...

137 0
ironshark/laravel-extendable

Traits for Laravel to add and manage custom Eloquent model fields.

11,037 24