2017 © Pedro Peláez
 

library eloquent-single-table-inheritance

Simple single table inheritance for eloquent models in Laravel & Lumen

image

oldtimeguitarguy/eloquent-single-table-inheritance

Simple single table inheritance for eloquent models in Laravel & Lumen

  • Monday, August 15, 2016
  • by oldtimeguitarguy
  • Repository
  • 1 Watchers
  • 1 Stars
  • 95 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 9 % Grown

The README.md

Eloquent Single Table Inheritance

This is a very simple implementation of single table inheritance for Eloquent (Laravel & Lumen)., (*1)

There are no attribute restrictions or anything that could be considered robust. There are other libraries that do those things quite well., (*2)

This simply allows you to have a single table that, when fetched, is thrown into an Eloquent model of your choice, defined by a column in that table (typically "type", which is the default keyed type column. You can customize this)., (*3)

For instance, imagine you have the following table (called people):, (*4)

id name sex
1 Fred boy
2 Jill girl

... and imagine you had the following classes:, (*5)

class Person extends StiParent
{
    protected $table = 'people';
    protected static $stiKey = 'sex';
    protected static $stiChildren = [
        'boy' => Boy::class,
        'girl' => Girl::class,
    ];
}

class Boy extends Person
{
    //
}

class Girl extends Person
{
    //
}

When you fetch all people, you will get a mix of boys & girls in the collection., (*6)

When you fetch just boys, you will get just boys., (*7)

When you fetch just girls, you will get just girls., (*8)

UNFORTUNATELY

  1. You cannot make your Person class abstract.
  2. You must specify the table on the parent
  3. When creating a hasMany association, you must make sure you specify the foreign key. Otherwise, it will try to automatically generate one from the class name.

The Versions

15/08 2016

dev-master

9999999-dev

Simple single table inheritance for eloquent models in Laravel & Lumen

  Sources   Download

MIT

by Karl Hepler

15/08 2016

v1.0.8

1.0.8.0

Simple single table inheritance for eloquent models in Laravel & Lumen

  Sources   Download

MIT

by Karl Hepler

08/08 2016

v1.0.7

1.0.7.0

Simple single table inheritance for eloquent models in Laravel & Lumen

  Sources   Download

MIT

by Karl Hepler

08/08 2016

v1.0.6

1.0.6.0

Simple single table inheritance for eloquent models in Laravel & Lumen

  Sources   Download

MIT

by Karl Hepler

08/08 2016

v1.0.5

1.0.5.0

Simple single table inheritance for eloquent models in Laravel & Lumen

  Sources   Download

MIT

by Karl Hepler

09/07 2016

v1.0.4

1.0.4.0

Simple single table inheritance for eloquent models in Laravel & Lumen

  Sources   Download

MIT

by Karl Hepler

09/07 2016

v1.0.3

1.0.3.0

Simple single table inheritance for eloquent models in Laravel & Lumen

  Sources   Download

MIT

by Karl Hepler

09/07 2016

v1.0.2

1.0.2.0

Simple single table inheritance for eloquent models in Laravel & Lumen

  Sources   Download

MIT

by Karl Hepler

09/07 2016

v1.0.1

1.0.1.0

Simple single table inheritance for eloquent models in Laravel & Lumen

  Sources   Download

MIT

by Karl Hepler

09/07 2016

v1.0.0

1.0.0.0

Simple single table inheritance for eloquent models in Laravel & Lumen

  Sources   Download

MIT

by Karl Hepler