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

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -