PHPackages                             igaster/eloquent-inheritance - 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. igaster/eloquent-inheritance

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

igaster/eloquent-inheritance
============================

Use a One-To-One (or One-To-Many) relation between a parent &amp; child Tables to simulate inheritance between Models

v1.0.1(10y ago)5150MITPHPPHP &gt;=5.4.0

Since Jan 5Pushed 10y ago2 watchersCompare

[ Source](https://github.com/igaster/eloquent-inheritance)[ Packagist](https://packagist.org/packages/igaster/eloquent-inheritance)[ Docs](https://github.com/igaster/eloquent-inheritance.git)[ RSS](/packages/igaster-eloquent-inheritance/feed)WikiDiscussions master Synced 3w ago

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

[![Laravel](https://camo.githubusercontent.com/5a1939c3fb1f6760124421638f59ab4ed15b6d03dbb30a6824df9af781880437/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e782d6f72616e67652e737667)](http://laravel.com)[![License](https://camo.githubusercontent.com/4661abfe916186acde514558e7f040833cb63ba7098401a51ce339cbb2b4cf9e/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](https://tldrlegal.com/license/mit-license)[![Downloads](https://camo.githubusercontent.com/eaa5f73d2e9ec2119a86177ab2459cc01f3e589f28c338f7f26c73271d18a2b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696761737465722f656c6f7175656e742d696e6865726974616e63652e737667)](https://packagist.org/packages/igaster/eloquent-inheritance)[![Build Status](https://camo.githubusercontent.com/4ed2a3080e31dac05b74e9bb26939575b569073d26745445bad2bed61f9e0fbd/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f696761737465722f656c6f7175656e742d696e6865726974616e63652e737667)](https://travis-ci.org/igaster/eloquent-inheritance)[![Codecov](https://camo.githubusercontent.com/30d32f3c892479e3e2ad3cd337372f1692fcba5e1497f565b20b464b614d53ce/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f696761737465722f656c6f7175656e742d696e6865726974616e63652e737667)](https://codecov.io/github/igaster/eloquent-inheritance)

Description
-----------

[](#description)

Eloquent Multiple Table Inheritance: Use a One-To-One (or One-To-Many) relation between a parent &amp; child Tables to simulate inheritance between Models.

Installation:
-------------

[](#installation)

Edit your project's composer.json file to require:

```
"require": {
    "igaster/eloquent-inheritance": "~1.0"
}
```

and install with `composer update`

Usage:
------

[](#usage)

#### Example Schema:

[](#example-schema)

```
// Model Foo is the parent model
Schema::create('foo', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('a');
});

// Model Bar inherits Foo.
Schema::create('bar', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('b');
    $table->integer('foo_id')->nullable(); // Foreign Key to Foo
});
```

#### Example Models:

[](#example-models)

Your models should use the `EloquentInherited` Trait

```
class Foo extends Eloquent
{
    use \igaster\EloquentInheritance\EloquentInherited;

	// ...
    public function fooMethod(){}
}

class Bar extends Eloquent
{
    use \igaster\EloquentInheritance\EloquentInherited;

	// ...
    public function barMethod(){}
}

class BarExtendsFoo extends igaster\EloquentInheritance\InheritsEloquent{
    // Set Parent/Child classes
    public static $parentClass = Foo::class;
    public static $childClass  = Bar::class;

    // You must declare Parent/Child keys explicity:
    public static $parentKeys = ['id','a'];
    public static $childKeys  = ['id','b','foo_id'];

    // Childs Foreign Key (points to Parent)
    public static $childFK  = 'foo_id';

    // You can add your functions / variables ...
    public function newMethod(){}
}
```

#### Usage:

[](#usage-1)

```
// Create a composite Model:
$fooBar = BarExtendsFoo::create([ // Creates and Saves Foo & Bar in the Database
    'a' => 1,
    'b' => 2,
]);

// Access Attributes:
$fooBar->a; // = 1 (from Foo model)
$fooBar->b; // = 2 (from Bar model)

// Call Methods:
$fooBar->fooMethod(); // from Foo Model
$fooBar->barMethod(); // from Bar Model
$fooBar->newMethod(); // from self

// Query as an Eloquent model:
$fooBar = BarExtendsFoo::find(1);
$fooBar = BarExtendsFoo::where('a',1)->first();
$fooBar = BarExtendsFoo::get();     // Collection of BarExtendsFoo

$fooBar->save();    // Saves Foo & Bar
$fooBar->delete();  // Deletes Foo & Bar
$fooBar->update([   // Updates Foo & Bar
    'a' => 10,
    'b' => 20,
]);
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

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 ~12 days

Total

2

Last Release

3810d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/55bf1c9bc1f0553b439f18852299833373f96eb6c1342434c74fb61c5aecd508?d=identicon)[igaster](/maintainers/igaster)

---

Top Contributors

[![igaster](https://avatars.githubusercontent.com/u/4586319?v=4)](https://github.com/igaster "igaster (22 commits)")

---

Tags

laravel-5.xtable inheritanceeloquent inheritancemultiple table inheritance

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/igaster-eloquent-inheritance/health.svg)

```
[![Health](https://phpackages.com/badges/igaster-eloquent-inheritance/health.svg)](https://phpackages.com/packages/igaster-eloquent-inheritance)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k54.1M11.1k](/packages/illuminate-database)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.1M23](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.4M2](/packages/glushkovds-phpclickhouse-laravel)[lemaur/eloquent-publishing

207.8k1](/packages/lemaur-eloquent-publishing)[laravel-liberu/laravel-gedcom

A package that converts gedcom files to Eloquent models

782.5k1](/packages/laravel-liberu-laravel-gedcom)

PHPackages © 2026

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