yzen.dev / request-data-adapter
Adapter for converting input data from Illuminate\Http\Request
Installs: 2 560
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 2
Requires
- php: ^7.0
- laravel/framework: 5.6.*|5.7.*|5.8.*|^6.0|^7.0
Requires (Dev)
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-10-30 01:48:10 UTC
README
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.
๐ Installation
The package can be installed via composer:
composer require yzen.dev/request-data-adapter
๐ 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" } }