New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

jaspaul/eloquent-sti

A simple single table inheritance library for eloquent.
6,743 5
Install
composer require jaspaul/eloquent-sti
Latest Version:1.0
PHP:>=7.2
Laravel:6
Older releases:5
License:MIT
Last Updated:Aug 17, 2021
Links: GitHub  ·  Packagist
Maintainer: Jaspaul

Eloquent STI (Single Table Inheritance)

Build
Status Coverage
Status Code Climate

Install

Via Composer

$ composer require jaspaul/eloquent-sti

Requirements

The following versions of PHP are supported by this version.

  • PHP 7.2
  • PHP 7.3
  • PHP 7.4

Usage

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

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

660,512,042 9,702
laravel/framework

The Laravel Framework.

625,568,548 34,998
laravel/tinker

Powerful REPL for the Laravel framework.

531,591,559 7,442
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

450,320,528 608
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

424,642,029 4,662

Version History

Version Released PHP Laravel License
1.0 >=7.2 ^6.0 MIT
v0.2 >=7.1 ^5.5|^5.6 MIT
v0.1 >=7.0 ^5.6 MIT