一对多关联中,如何在多个 car 表中查询到 thief 表的名字 name,语句该如何写?
- 比如 Thief 表有名字 name,
- 一对多关联中,如何在多个 car 表中查询到 thief 表的名字 name,语句该如何写?
-
现在是
$car = Car::get(); 想得到 每个 car 的 thief name
Eloquent 模型:
class Thief
{
public function cars()
{
return $this->hasMany(Car::class);
}
}
class Car
{
public function thief()
{
return $this->belongsTo(Thief::class);
}
}
推荐文章: