php - Laravel Eager Loading Polymorphic Relationships -
trying eager load model , it's related model related model returns null though has related data.
group model polymorphic 1:1 either game or gamer.
group model relationship:
public function groupable() { return $this->morphto(); }
game model relationship:
public function group() { return $this->morphone('group', 'groupable'); }
gamer model relationship:
public function group() { return $this->morphone('group', 'groupable'); }
query load group game:
$group = group::wheresubdomain($id)->first(); $game = $group->game;
group returns group game returns null.
here sample database entry groups table:
id subdomain groupable_id groupable_type 5 starmade 10 game
here sample database entry games table:
id genre rating 10 7 4.5
not sure going wrong have no game returned.
try this. might help.
public function groupable() { return $this->morphto('groupable'); }
i had problem earlier, maybe have same prob me. did laravel finds columns needs for.
Comments
Post a Comment