Last active
September 14, 2017 02:32
-
-
Save hailwood/e30ac7a8a2367c762b05c12ab13d2573 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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