PHPackages                             rizkussef/laravel-snake-to-camel-case - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. rizkussef/laravel-snake-to-camel-case

ActiveLibrary[API Development](/categories/api)

rizkussef/laravel-snake-to-camel-case
=====================================

A Laravel middleware package to automatically convert API response keys from snake\_case to camelCase for frontend compatibility, and optionally convert request keys from camelCase to snake\_case

v1.0.8(9mo ago)2543—0%MITPHPPHP &gt;=8.1

Since Jul 21Pushed 9mo agoCompare

[ Source](https://github.com/RizkUssef/laravel-snake-to-camel-case)[ Packagist](https://packagist.org/packages/rizkussef/laravel-snake-to-camel-case)[ RSS](/packages/rizkussef-laravel-snake-to-camel-case/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (9)Used By (0)

🐍🔁🐫 Laravel Snake-to-Camel Case Middleware
==========================================

[](#-laravel-snake-to-camel-case-middleware)

[![Packagist Version](https://camo.githubusercontent.com/a359173d73433db7c453d6e6c4dcdaa8823216ee78096bebee4b6fcca33dd5c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72697a6b75737365662f6c61726176656c2d736e616b652d746f2d63616d656c2d636173652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rizkussef/laravel-snake-to-camel-case)[![Total Downloads](https://camo.githubusercontent.com/002c7b40436b4ee766be999c186a661d2f85ee111811b0b42e26a00e8eb698c9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72697a6b75737365662f6c61726176656c2d736e616b652d746f2d63616d656c2d636173652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rizkussef/laravel-snake-to-camel-case)[![License](https://camo.githubusercontent.com/6c711032aff1ca0eb6b211aa6cb3649ce7fd64a7714e1181d4bb457f9680e7cf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Install with Composer](https://camo.githubusercontent.com/73b195f4f92bfc085031fcffa611fd5be42bf0a374e37ccdcc3575fe8520f274/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f496e7374616c6c253230776974682d436f6d706f7365722d626c75653f7374796c653d666c61742d737175617265266c6f676f3d636f6d706f736572)](https://packagist.org/packages/rizkussef/laravel-snake-to-camel-case)

---

✨ What is this?
---------------

[](#-what-is-this)

A Laravel package that **automatically converts API keys** between `snake_case` and `camelCase`:
✔ **Incoming Requests:** Converts `camelCase` → `snake_case` (for Eloquent models &amp; DB consistency).
✔ **Outgoing Responses:** Converts `snake_case` → `camelCase` (for React, Vue, or any frontend apps).

Perfect for **clean API responses** and **JavaScript-friendly keys**! 🚀

---

✅ Features
----------

[](#-features)

- 🔄 **Two-way conversion**: Request &amp; Response.
- 🔍 Works on **nested arrays &amp; JSON**.
- 🔗 Applies to **all routes or only API routes** (configurable).
- ⚡ **Plug &amp; play** using Laravel’s **package auto-discovery**.
- 🛠 **Fully configurable** via `config/snake-to-camel.php`.

---

📦 Installation
--------------

[](#-installation)

Require the package via Composer:

```
composer require rizkussef/laravel-snake-to-camel-case
```

---

⚙️ Configuration
----------------

[](#️-configuration)

Publish the config file:

```
php artisan vendor:publish --tag=config
```

Then edit `config/snake-to-camel.php`:

```
return [
    'convert_response' => true, // Enable snake_case → camelCase for responses
    'convert_request'  => true, // Enable camelCase → snake_case for requests
    'apply_to'         => 'all', // Options: 'all' | 'api' | 'web'
];
```

✅ You can also override these settings in `.env`:

```
SNAKE_TO_CAMEL_CONVERT_RESPONSE=true
SNAKE_TO_CAMEL_CONVERT_REQUEST=true

```

---

🔍 How It Works
--------------

[](#-how-it-works)

### ✅ Example Request (Frontend → Laravel)

[](#-example-request-frontend--laravel)

**Before:**

```
{
    "firstName": "Rizk",
    "lastName": "Ussef"
}
```

**After Middleware (Laravel receives):**

```
{
    "first_name": "Rizk",
    "last_name": "Ussef"
}
```

---

### ✅ Example Response (Laravel → Frontend)

[](#-example-response-laravel--frontend)

**Before:**

```
{
    "first_name": "Rizk",
    "last_name": "Ussef"
}
```

**After Middleware (Frontend receives):**

```
{
    "firstName": "Rizk",
    "lastName": "Ussef"
}
```

---

🏗 Usage
-------

[](#-usage)

No manual registration needed. Laravel auto-discovers the service provider:
`Rizkussef\LaravelSnakeToCamelCase\Providers\SnakeToCamelServiceProvider`

The middleware automatically applies to:

- ✅ All routes (if `apply_to` = `all`)
- ✅ Only API routes (if `apply_to` = `api`)

---

📌 Requirements
--------------

[](#-requirements)

- PHP 8.1+
- Laravel 10.x | 11.x

---

📄 License
---------

[](#-license)

This package is open-source under the **MIT license**.
See [LICENSE](https://chatgpt.com/c/LICENSE) for details.

---

⭐ Support
---------

[](#-support)

If you like this package, please **star the repo** on [GitHub](https://github.com/rizkussef/laravel-snake-to-camel-case) ⭐
Contributions and PRs are welcome!

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance56

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

8

Last Release

294d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f71fc860d07c78f9ceb026be3ea529c3cc27957b6e2631f778c68a2d01761ed?d=identicon)[RizkUssef](/maintainers/RizkUssef)

---

Top Contributors

[![RizkUssef](https://avatars.githubusercontent.com/u/139924623?v=4)](https://github.com/RizkUssef "RizkUssef (15 commits)")

---

Tags

responserequestjsonmiddlewareapilaraveltransformsnake casecamelcaselaravel middlewarecase conversionkey conversioncamel snake

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rizkussef-laravel-snake-to-camel-case/health.svg)

```
[![Health](https://phpackages.com/badges/rizkussef-laravel-snake-to-camel-case/health.svg)](https://phpackages.com/packages/rizkussef-laravel-snake-to-camel-case)
```

###  Alternatives

[obiefy/api-response

Simple Laravel package to return Json responses.

17324.6k](/packages/obiefy-api-response)[nilportugues/laravel5-json-api-dingo

Laravel5 JSONAPI and Dingo together to build APIs fast

311.5k](/packages/nilportugues-laravel5-json-api-dingo)[nilportugues/laravel5-haljson

Laravel 5 HAL+JSON API Transformer Package

151.0k](/packages/nilportugues-laravel5-haljson)[nicklaw5/larapi

A simple Laravel 5 class for handling json api responses.

111.5k](/packages/nicklaw5-larapi)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
