kjos/kjos-laravel-parameter-mapper

ParameterMapper tool for Laravel and other

Installs: 12

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/kjos/kjos-laravel-parameter-mapper

v1.3.4 2025-11-17 17:41 UTC

README

Packagist Version PHP License

🌐 Multilanguage | Multilingual

πŸ‡¬πŸ‡§ English

Kjos Laravel Parameter Mapper

A Laravel package that allows you to dynamically map GET and POST parameters sent by the client to your application's backend keys, and vice versa. Useful for hiding the actual field names from the user or for standardizing your APIs.

Installation

For Laravel 12 or higher:

composer require kjos/kjos-laravel-parameter-mapper

Publish the configuration

php artisan vendor:publish --tag=parametermap

Configuration

return [
    'map' => [
        // frontParam => backendParam
        'id_ur'   => 'user_id',
        'name_lt' => 'last_name',
        'ae'      => 'age',
    ],

    // Valeurs spΓ©cifiques Γ  mapper (ex: search=id_us => search=user_id)
    'values-to-map' => [
          'search',
    ],
    
    // Mapper les clΓ©s dans des tableaux (ex: sort[id_us] => sort[user_id])
        'array-keys-to-map' => [
            'sort',
        ],

        'reject-knowns' => true,
];

##Middleware

use Kjos\ParameterMapper\Middleware\MapRequestParameters;
Route::middleware([MapRequestParameters::class])

Class ParameterMapper

use Kjos\ParameterMapper\Support\ParameterMapper;

// Map front -> back
$mapped = ParameterMapper::apply([ 
'id_ur' => 1, 
'name_lt' => 'Koffi', 
'ae' => 10, 
'sort' => ['id_ur' => 'asc'], 
'search' => 'id_ur',
]);

// Map back -> front
$frontend = ParameterMapper::reverse([ 
'user_id' => 1, 
'last_name' => 'Koffi', 
'age' => 10, 
'sort' => ['user_id' => 'asc'], 
'search' => 'user_id',
]);

Use in Factories

$datas = ParameterMapper::reverse([ 
'user_id' => 1, 
'last_name' => 'Koffi', 
'age' => 10, 
]);

Becomes:

[
'id_ur' => 1,

'name_lt' => 'Koffi',

'ae' => 10,

]

API Example

Request:

GET /api/admins?search=id_us&sort[id_us]=asc

Automatically transformed into:

[
'search' => 'user_id',

'sort' => ['user_id' => 'asc']
];

πŸ”’ reject-knowns β€” Reject internal parameters

The reject-knowns parameter allows you to automatically reject any request that contains a parameter corresponding to an internal backend key.

Purpose

To prevent users from directly sending backend (internal) field names that are normally hidden behind the front-end map.

For example, if you have this map:

'map' => [
'id_ur' => 'user_id',
'name_lt' => 'last_name',
'ae' => 'age',
],

and reject-knowns is enabled:

'reject-knowns' => true,

Then a request like:

GET /api/admins?user_id=1 will be rejected with an HTTP 404 error, because user_id is an internal parameter and should not be exposed on the front end.

Comment to enable it

In the configuration file config/parameter-mapper.php

<?php

return [
'map' => [
'id_ur' => 'user_id',
'name_lt' => 'last_name',
'ae' => 'age',
],

// Reject known backend parameters
'reject-knowns' => true,
];

Map the response

In the configuration file config/parameter-mapper.php

<?php

return [
'map' => [
    ...
],

// Will map the response
'map-response' => true,
];

Schema

Schema

πŸ“ Directory Structure

project-root/ 
β”œβ”€β”€ CHANGELOG.md 
β”œβ”€β”€ LICENSE 
β”œβ”€β”€ README.md 
β”œβ”€β”€ composer.json 
β”œβ”€β”€ composer.lock 
β”œβ”€β”€ config 
β”‚ └── parameter-mapper.php 
β”œβ”€β”€ grumphp.yml 
β”œβ”€β”€ phpunit.xml 
β”œβ”€β”€ pint.json 
β”œβ”€β”€ schema.png 
β”œβ”€β”€ src 
β”‚ β”œβ”€β”€ Middleware 
β”‚ β”œβ”€β”€ ParameterMapperServiceProvider.php 
β”‚ └── Support 
β”œβ”€β”€ tests 
β”‚ β”œβ”€β”€ ExampleTest.php 
β”‚ β”œβ”€β”€ Feature 
β”‚ β”œβ”€β”€ Pest.php 
β”‚ β”œβ”€β”€ TestCase.php 
β”‚ └── Unit

πŸ‘€ Author

Maintained by Jean Koffi

πŸ“„ License

MIT Β© kjos/kjos-laravel-parameter-mapper

🀝 Call for contributions

This project is open to contributions! Are you a developer, passionate about Laravel, or interested in multi-tenant architecture?

-Fork the project

  • Create a branch (klpm/my-feature)

  • Make a PR πŸ§ͺ