Middleware for automatic case transformation of request and response data key in Laravel applications.

v1.0.2 2024-06-09 19:39 UTC

This package is auto-updated.

Last update: 2024-06-09 19:42:34 UTC


Middleware for automatic case transformation of request and response data in Laravel applications.

Latest Version on Packagist GitHub Tests Action Status issues stars GitHub license Total Downloads


It is a common convention to work with camel case in Javascript and most front-end technologies and snake case in PHP (Backend), this package makes that a breeze as you can work with your data columns just as you like in laravel and your responces or request data are automatically converted to any case.


Install Laravel Key Case, run the following command in your terminal:

composer require teners/laravel-key-case

Publish the package configuration file

php artisan vendor:publish --provider="Teners\LaravelKeyCase\LaravelKeyCaseServiceProvider" --tag="key-case-config"

You can then customize what case to use for each of the request and the response data.

Use the middlewares

This package comes with two middlewares

  • TransformResponseMiddleware: Transforms response data
  • TransformRequestMiddleware: Transforms request data

You can register their aliases (or use them dirrectly on the api route group if you are using them through the api) for easy reference elsewhere in your app:

In Laravel 11 open /bootstrap/app.php and register them there:

    ->withMiddleware(function (Middleware $middleware) {
        $middleware->api(append: [

    // Or to use on individual routes
    ->withMiddleware(function (Middleware $middleware) {
            'convert-response-key' => \Teners\LaravelKeyCase\Http\Middleware\TransformResponseMiddleware:class,

In Laravel 9 and 10 you can add them in /app/Http/Kernel.php:

    protected $middlewareGroups = [
        'web' => [

        'api' => [

    // Or to use on individual routes

    // Laravel 9 uses $routeMiddleware = [
    //protected $routeMiddleware = [
    // Laravel 10+ uses $middlewareAliases = [
    protected $middlewareAliases = [
        // ...
        'convert-response-key' => \Teners\LaravelKeyCase\Http\Middleware\TransformResponseMiddleware:class,


Contributions are welcome via Pull Requests on Github.

  • Please document any change you made as neccesary in the README.md.
  • Pleas make only one pull request per feature/fix.


Please report any issue you encounter in using the package through the Github Issues tab.


composer test



Contributors list will be added here


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