Have you found a solution yet for your problem, because I'm facing the same problem..
Mar 12, 2015
13
Level 1
Laravel 5 - Eloquent Models Inheritance (Accessing columns from abstract parent class in derived classes)
Hello.
I'm working on a little project and ran across a problem. (See the ERD for the design).
I want to, for example, access the "name" of the creatures table in the Monster Context.
abstract class Creature extends Model {...}
class Character extends Creature {...}
class Monster extends Creature {...}
If I don't make the parent class (Creature) abstract, I can do a workaround like this:
class Monster extends Creature {
public function getStatblock() {
return parent::getStatblock();
}
}
class Creature extends Model {
public function getStatblock() {
$statblock = [];
$statblock["name"] = $this->creature->name;
return $statblock;
}
}
As you can see, I have to resolve the FK of the derived class in the parent class, to get to the actual instance of the object. It looks really odd though and I want to have something more elegant.

edit: I do not want to use single table inheritance unless I really have to. I would like to maintain a one table per class design.
Please or to participate in this conversation.