2017 © Pedro Peláez
 

library eloquent-sti

A simple single table inheritance library for eloquent.

image

jaspaul/eloquent-sti

A simple single table inheritance library for eloquent.

  • Wednesday, May 2, 2018
  • by Jaspaul
  • Repository
  • 1 Watchers
  • 4 Stars
  • 963 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 151 % Grown

The README.md

Eloquent STI (Single Table Inheritance)

Build
Status Coverage
Status Code Climate, (*1)

Install

Via Composer, (*2)

``` bash $ composer require jaspaul/eloquent-sti, (*3)


## Requirements The following versions of PHP are supported by this version. * PHP 7.2 * PHP 7.3 * PHP 7.4 ## Usage ```php <?php use Tests\Helpers\User; use Tests\Helpers\Administrator; use Jaspaul\EloquentSTI\Inheritable; use Illuminate\Database\Eloquent\Model; class User extends Model { use Inheritable; /** * Provides a map of types to resolve for this object. The format is: * 'user' => User::class, * 'administrator' => Administrator::class * * @var array */ protected $types = [ 'user' => User::class, 'administrator' => Administrator::class ]; }
<?php

class Administrator extends User
{
}

Now when you select users through the User model, they'll be returned with the associated type. For instance if you have a record in the users table with the type administrator, an Administrator object will be returned when you run User::where('type', 'administrator')->first()., (*4)

The Versions