laravel belongsTo gives null

前端 未结 3 1914
小蘑菇
小蘑菇 2021-01-27 06:55

belongsTo relation in laravel is returning null

public function games(){
    return $this->belongsTo(\'App\\Models\\Game\');
  }

but when i

3条回答
  •  旧巷少年郎
    2021-01-27 07:43

    It looks like the name of your method "games" may be the issue. The assumption with a 1-to-many relationship is that the parent class is singular while the child is plural. Try changing the name "games" to "game" and the key argument shouldn't be required.

    At this point, I'm guessing Laravel is thinking your id key would be "games_id".

提交回复
热议问题