A simple single table inheritance library for eloquent.

v0.2 2018-04-20 19:08 UTC


Build Status Coverage Status Code Climate


Via Composer

$ composer require jaspaul/eloquent-sti


The following versions of PHP are supported by this version.

  • PHP 7.1
  • PHP 7.2



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

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().