HasManyThrough
hasManyThrough()を利用すると、別のテーブルを跨いだ一対多リレーションを定義することができます。
下記の例では、顧客(Customer)モデルに対し、車(Car)モデルを経由して、車検(Inspection)モデルを関連付けています。
class Customer extends Model
{
public function inspections()
{
return $this->hasManyThrough(Inspection::class, Car::class);
}
}