Skip to content

Instantly share code, notes, and snippets.

@hailwood
Last active September 14, 2017 02:32
Show Gist options
  • Save hailwood/e30ac7a8a2367c762b05c12ab13d2573 to your computer and use it in GitHub Desktop.
Save hailwood/e30ac7a8a2367c762b05c12ab13d2573 to your computer and use it in GitHub Desktop.
class Creature extends Model {
protected $with = [
'entity'
];
public function entity(){
return $this->morphTo();
}
public function __get($key)
{
return $this->getAttribute($key) ?: $this->entity->getAttribute($key);
}
}
abstract class CreatureType extends Model {
protected $with = [
'creature';
];
public function creature(){
return $this->morphOne(Creature::class, 'entity');
}
public function __get($key)
{
return $this->getAttribute($key) ?: $this->creature->getAttribute($key);
}
}
class Human extends CreatureType {}
class Lion extends CreatureType {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment