【发布时间】:2020-06-02 15:21:15
【问题描述】:
我在 Laravel 上学习雄辩的关系,我在 hasonethrough 上遇到了问题
通过使用与 Laravel 文档相同的表格设计
tables
mechanics (id, name)
cars (id, model, mechanic_id)
owners (id, name, car_id)
然后我在 mechanic model 上定义关系来访问车主
class Mechanic extends Model
{
public function carOwner() {
return $this->hasOneThrough('App\Owner', 'App\Car');
}
}
这将返回
array:4 [▼
"id" => 1
"name" => "Ricky"
"car_id" => 1
"laravel_through_key" => 1
]
我的问题是我可以使用我的hasOnethrough 关系获取汽车模型吗?
【问题讨论】: