PHPackages                             stidges/laravel-db-normalizer - 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. [Database &amp; ORM](/categories/database)
4. /
5. stidges/laravel-db-normalizer

ActiveLibrary[Database &amp; ORM](/categories/database)

stidges/laravel-db-normalizer
=============================

Normalize all database results to one unified interface, to make swapping repositories a breeze.

0.1.0(12y ago)70175MITPHPPHP &gt;=5.4.0

Since Mar 12Pushed 12y ago6 watchersCompare

[ Source](https://github.com/stidges/laravel-db-normalizer)[ Packagist](https://packagist.org/packages/stidges/laravel-db-normalizer)[ Docs](https://github.com/stidges/laravel-db-normalizer)[ RSS](/packages/stidges-laravel-db-normalizer/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Laravel DB Normalizer
=====================

[](#laravel-db-normalizer)

[![Latest Stable Version](https://camo.githubusercontent.com/bd87dc47ac2c69c3ab03d6edf2c309db82af88fcc6b64e06575388658d538901/68747470733a2f2f706f7365722e707567782e6f72672f737469646765732f6c61726176656c2d64622d6e6f726d616c697a65722f76657273696f6e2e706e67)](https://packagist.org/packages/stidges/laravel-db-normalizer) [![Total Downloads](https://camo.githubusercontent.com/d9813b802e5bc8aacaa97449c26680d4536678cc36d4576dec564569b3de4c42/68747470733a2f2f706f7365722e707567782e6f72672f737469646765732f6c61726176656c2d64622d6e6f726d616c697a65722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/stidges/laravel-db-normalizer) [![Build Status](https://camo.githubusercontent.com/a745ddcf3fa384b26ff9f029509ca9653ff9e091a3a9b6f3b06ca735cca54085/68747470733a2f2f7472617669732d63692e6f72672f737469646765732f6c61726176656c2d64622d6e6f726d616c697a65722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/stidges/laravel-db-normalizer) [![License](https://camo.githubusercontent.com/44ebd12829fcf0c399914f13ea4f1c1da700931422c73ed59bcf83690948d43b/68747470733a2f2f706f7365722e707567782e6f72672f737469646765732f6c61726176656c2d64622d6e6f726d616c697a65722f6c6963656e73652e706e67)](https://packagist.org/packages/stidges/laravel-db-normalizer)

This [Laravel](http://www.laravel.com) package allows you to easily swap out your repository implementations, by providing a unified interface to your database results.

It intercepts your results and turns them into collections and entities. That way, whether you are using Eloquent, the Query Builder or any other implementation, the results will be the same!

[![Result](https://camo.githubusercontent.com/79ae46c930137292e62bc409c1af08dbbcf781fc277ff40991e06755fa5e3fdd/687474703a2f2f692e696d6775722e636f6d2f593072457959712e6a7067)](https://camo.githubusercontent.com/79ae46c930137292e62bc409c1af08dbbcf781fc277ff40991e06755fa5e3fdd/687474703a2f2f692e696d6775722e636f6d2f593072457959712e6a7067)

Getting Started
---------------

[](#getting-started)

This package can be installed through [Composer](http://www.getcomposer.org), just add it to your composer.json file:

```
{
    "require": {
        "stidges/laravel-db-normalizer": "0.*"
    }
}
```

After you have added it to your composer.json file, make sure you update your dependencies:

```
composer install
```

Next, you can do either of these two:

##### 1. Enable auto-normalization:

[](#1-enable-auto-normalization)

By registering this package's ServiceProvider class, all the queries you run will be automatically normalized to the unified `Collection` and `Entity` classes. Add the following line to your `app/config/app.php` file:

```
'Stidges\LaravelDbNormalizer\DbNormalizerServiceProvider',
```

When using Eloquent models, they should extend the `NormalizableModel` class:

```
use Stidges\LaravelDbNormalizer\NormalizableModel;

class User extends NormalizableModel
{
    // ...
}
```

##### 2. Disable auto-normalization:

[](#2-disable-auto-normalization)

If you would rather want some more control, don't register the ServiceProvider. That way you can control when the results get cast to the classes. To do this, `use` the Normalizer class. **Make sure you always pass an array to the normalizer!**

```
use Stidges\LaravelDbNormalizer\Normalizer;

//...

// Example using the query builder
$result = DB::table('users')->get();
// ... Do stuff with the result.
$normalized = with(new Normalizer)->normalize($result);

// Example using Eloquent
$user = User::find(1);
// ... Do stuff with the user.
$normalized = with(new Normalizer)->normalize($user->toArray());

// Example using Eloquent collection
$users = User::all();
// ... Do stuff with the users.
$normalized = with(new Normalizer)->normalize($users->toArray());
```

Using the normalized results
----------------------------

[](#using-the-normalized-results)

This package provides 2 classes:

1. A `Collection` class. As it currently stand, this class just extends Laravel's `Illuminate\Support\Collection` class.
2. An `Entity` class. This class can contain nested entities and collections (relations). It provides a fluent interface to accessing the attributes of the entity, and can be cast to an array or JSON using the familiar `toJson` and `toArray` methods. On top of that, it provides a `getDirtyAttributes()` function, which allows you to get all the attributes that were changed after creation.

Example usage
-------------

[](#example-usage)

For examples on how to use the package, please view the `examples` directory!

Contributing
------------

[](#contributing)

All suggestions and pull requests are welcome! If you make any substantial changes, please provide tests along with your pull requests!

License
-------

[](#license)

Copyright (c) 2014 Stidges - Released under the [MIT license](LICENSE).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

4441d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7d3026e6eab9c0c75c7315cd4b8ea41d1ab9e0b7665a1f9f9396e2f1f716deba?d=identicon)[stidges](/maintainers/stidges)

---

Top Contributors

[![stidges](https://avatars.githubusercontent.com/u/4399967?v=4)](https://github.com/stidges "stidges (8 commits)")

---

Tags

databaselaravelphpnormalizerlaraveleloquentdbrepositories

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stidges-laravel-db-normalizer/health.svg)

```
[![Health](https://phpackages.com/badges/stidges-laravel-db-normalizer/health.svg)](https://phpackages.com/packages/stidges-laravel-db-normalizer)
```

###  Alternatives

[torann/laravel-repository

Base repository implementation for Laravel

88497.8k2](/packages/torann-laravel-repository)[czim/laravel-repository

Repository for Laravel (inspired by and indebted to Bosnadev/Repositories)

54110.0k4](/packages/czim-laravel-repository)[dannyweeks/laravel-base-repository

An abstract repository class for your Eloquent repositories that requires minimal config to get started.

202.0k](/packages/dannyweeks-laravel-base-repository)[chocofamilyme/laravel-tarantool

A Tarantool based Eloquent ORM and Query builder for Laravel

182.3k](/packages/chocofamilyme-laravel-tarantool)

PHPackages © 2026

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