【发布时间】:2018-12-24 10:08:47
【问题描述】:
我的表结构是这样的:
farmers
id
name
education_id (used to capture max education)
educations (names of the education levels like BS / MS / PhD etc.)
id
name
我尝试了以下代码但失败 -
In farmers model (app/fermers.php) I added this code:
public function education()
{
return $this->hasOne(Educations::class);
}
如何建立关系?
【问题讨论】:
-
"失败" 什么失败? "Educations::class" 你的模型叫
Educations?你use App\Educations;在文件顶部吗? -
在您的情况下,您必须使用belongsTo 而不是hasOne Cause of Educatoin Farmers table education_id belongsTo Education Table