PHPackages                             isaacqc/laravel-single-table-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. isaacqc/laravel-single-table-inheritance

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

isaacqc/laravel-single-table-inheritance
========================================

A package that contains a model for single table inheritance with eloquent(laravel orm)

1.0.4(8y ago)015MITPHPPHP &gt;=5.3.0

Since Aug 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/isaacqc/laravel-single-table-inheritance)[ Packagist](https://packagist.org/packages/isaacqc/laravel-single-table-inheritance)[ RSS](/packages/isaacqc-laravel-single-table-inheritance/feed)WikiDiscussions 1.0 Synced 2mo ago

READMEChangelog (2)DependenciesVersions (7)Used By (0)

\#Laravel-Single-Table-Inheritance

Mapping domain model into relational database is hard. For this reason there are many ways to do that. Single table inheritance is one of them. the stengths of this approach are:

- Is simple
- Moving column between hierarchy doesn't require db changes But there are some weakness in that approach:
- There is no metadata to define which attribute belongs to which subtype: looking table directly is a bit weird
- The table will quiclky become a bottleneck if you create many hierarchies
- You waste some space with empty columns(depending on dbms compression of nulls)

Laravel-Single-Table-Inheritance is a package that offer a simple and basic model to handle single table inheritance with eloquent ORM. Be aware this pattern come from Martin Fowler(Patterns of Enterprise Application Architecture). For more information follow this link: [Single Table Inheritance](http://martinfowler.com/eaaCatalog/index.html). Also check my post about [Single table inheritance](http://www.jacopobeschi.com/post/php-table-inheritance).

- **Author**: Jacopo Beschi
- **Version**: 1.0.2

[![Build Status](https://camo.githubusercontent.com/33941f443cd8f5784fb3401024224e84fbab9f74baa31bb1e4ff9923f7620c87/68747470733a2f2f7472617669732d63692e6f72672f696e747269702f6c61726176656c2d73696e676c652d7461626c652d696e6865726974616e63652e706e67)](https://travis-ci.org/intrip/laravel-single-table-inheritance)

Requirements
------------

[](#requirements)

- PHP &gt;= 5.4
- Composer
- Laravel framework 4.2+ **Note**: if you need to use laravel 4.0.\* or 4.1.\* please download the version 1.0.1 of the package

\##Installation with Composer

To install Laravel-Single-Table-Inheritance with Composer, add this line to your composer.json file in the `require field:

"jacopo/laravel-single-table-inheritance": "1.0.\*"

Congratulations! You succesfully installed the package.

\##Usage

To use the package you need to extend `Jacopo\LaravelSingleTableInheritance\Models\Model` on your model class. Then you need to change the following attributes of your model:

- protected $table\_type
- protected static $table\_type\_field
- protected $my\_attributes

The field `$table_type` contains the string that will be saved in the `$table_type_field` column to distinguish the current model to the other models saved in the table. The field `$my_attributes` is an array that contains all the attributes that belongs to the current model(except the eloquent attributes created\_at updated\_at and deleted\_at which are auto setted). For a better understanding on how to setup your model you should definatelly look in the [examples](https://github.com/intrip/laravel-single-table-inheritance/tree/master/examples) folder.

Keep in mind that each model can fetch the data only from the rows that belongs to his type even if all data is stored and the same table! You can only set and get attributes related to the current model and his parents. If you want to fetch all the data inside the table you should create custom queries.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 86% 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 ~254 days

Total

5

Last Release

3207d ago

### Community

---

Top Contributors

[![intrip](https://avatars.githubusercontent.com/u/1753245?v=4)](https://github.com/intrip "intrip (37 commits)")[![isaactinghong](https://avatars.githubusercontent.com/u/1496881?v=4)](https://github.com/isaactinghong "isaactinghong (6 commits)")

### Embed Badge

![Health badge](/badges/isaacqc-laravel-single-table-inheritance/health.svg)

```
[![Health](https://phpackages.com/badges/isaacqc-laravel-single-table-inheritance/health.svg)](https://phpackages.com/packages/isaacqc-laravel-single-table-inheritance)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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