PHPackages                             thibaud-dauce/eloquent-inheritance-storage - 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. thibaud-dauce/eloquent-inheritance-storage

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

thibaud-dauce/eloquent-inheritance-storage
==========================================

Easily manage inheritance with Eloquent ORM

v0.1(11y ago)818[2 issues](https://github.com/ThibaudDauce/EloquentInheritanceStorage/issues)MITPHPPHP &gt;=5.4.0

Since Jul 28Pushed 11y ago3 watchersCompare

[ Source](https://github.com/ThibaudDauce/EloquentInheritanceStorage)[ Packagist](https://packagist.org/packages/thibaud-dauce/eloquent-inheritance-storage)[ RSS](/packages/thibaud-dauce-eloquent-inheritance-storage/feed)WikiDiscussions master Synced 3d ago

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

Eloquent Inheritance Storage
============================

[](#eloquent-inheritance-storage)

[![Build Status](https://camo.githubusercontent.com/bc39ba19e5a5457667ccbcc8a02bcdfe146381a32badb8e40b84c962e93d377e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f5468696261756444617563652f456c6f7175656e74496e6865726974616e636553746f726167652f6d61737465722e7376673f7374796c653d666c6174)](https://travis-ci.org/ThibaudDauce/EloquentInheritanceStorage)[![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](LICENSE.md)

Introduction
------------

[](#introduction)

Eloquent Inheritance Storage is extending Eloquent ORM in order to provide support for models extending other models. It allows you to store and retrieve parent and child models easily.

This package is an extension of the `single table inheritance` pattern. It uses views to combine data coming from several tables of a class hierarchy. By doing this we are avoiding tables with many NULL values.

Installation
------------

[](#installation)

[PHP](https://php.net) 5.4+ and [Laravel](http://laravel.com) 4.2+ are required.

To get the latest version of Eloquent Inheritance Storage, simply require `"thibaud-dauce/eloquent-inheritance-storage": "0.*"` in your `composer.json` file. You'll then need to run `composer install` or `composer update` to download it and have the autoloader updated.

Once Eloquent Inheritance Storage is installed, you need to register the service provider. Open up `app/config/app.php` and add the following to the `providers` key.

- `'ThibaudDauce\EloquentInheritanceStorage\EloquentInheritanceStorageServiceProvider'`

You can register the `InheritanceStorage` facade in the `aliases` key of your `app/config/app.php` file if you like.

- `'InheritanceStorage' => 'ThibaudDauce\EloquentInheritanceStorage\Facades\InheritanceStorage'`

Model configuration example
---------------------------

[](#model-configuration-example)

### Presentation

[](#presentation)

Let's imagine that I'm currently developing a video game with different kind of characters. I will have some basic characters and some specialized ones:

- A `warrior` will be a character with a `rage` attribute.
- A `wizard` will be a character with a `magic` attribute.

My class hierarchy will be the following:

- `Character`: id, name.
    - `Warrior` extends `Character`: id, name, rage.
    - `Wizard` extends `Character`: id, name, magic.

### Models

[](#models)

Apply the `ThibaudDauce\EloquentInheritanceStorage\ParentTrait` to the `Character` model (the parent class).

```
