我有2個控制器和模型:Laravel方法[的hasMany]不存在
- 用戶控制器&模型
- 英雄控制器&模型
每個用戶可以有無限的英雄 - 這意味着他們之間的關係是一對多。
在我UserController中我創建了以下方法:
/**
* Get the heroes of the user.
*/
public function heroes()
{
return $this->hasMany(Hero::Class);
}
,而在我的HeroController我創造了這個方法:
/**
* Get the user that owns the hero.
*/
public function user()
{
return $this->belongsTo(User::class)
}
將此添加到我的路線文件:
Route::get('userHeroes', '[email protected]');
並返回此錯誤:
{"error":{"message":"Method [hasMany] does not exist.","status_code":500}}
出了什麼問題..?