<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
findyouractivity / single-table-inheritance example snippets
use Nanigans\SingleTableInheritance\SingleTableInheritanceTrait;
class Vehicle extends Model
{
use SingleTableInheritanceTrait;
protected $table = "vehicles";
protected static $singleTableTypeField = 'type';
protected static $singleTableSubclasses = [Car::class, Truck::class];
}
class Car extends Vehicle
{
protected static $singleTableType = 'car';
}
class Truck extends Vehicle
{
protected static $singleTableType = 'truck';
}
use Nanigans\SingleTableInheritance\SingleTableInheritanceTrait;
class Vehicle extends Model
{
use SingleTableInheritanceTrait;
protected $table = "vehicles";
protected static $singleTableTypeField = 'type';
protected static $singleTableSubclasses = [MotorVehicle::class, Bike::class];
}
class MotorVehicle extends Vehicle
{
protected static $singleTableSubclasses = [Car::class, Truck::class];
}
class Car extends MotorVehicle
{
protected static $singleTableType = 'car';
}
class Truck extends MotorVehicle
{
protected static $singleTableType = 'truck';
}
class Bike extends Vehicle
{
protected static $singleTableType = 'bike';
}
class Vehicle extends Model
{
protected static $persisted = ['color']
}
class MotorVehicle extends Vehicle
{
protected static $persisted = ['fuel']
}
class Vehicle extends Model
{
protected static $persisted = ['color', 'owner_id'];
public function owner()
{
return $this->belongsTo('User', 'owner_id');
}
}
/**
* Whether the model should throw an InvalidAttributesException if non-persisted
* attributes are encountered when saving or hydrating a model.
* If not set, it will default to false.
*
* @var boolean
*/
protected static $throwInvalidAttributeExceptions = true;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.