Laravel模型集合返回中的嵌套With()

时间:2018-09-01 02:00:59

标签: laravel laravel-5 eloquent

我有一个这样返回的集合:

$scheduleLoads = Load::with('shipment','driver','tractor');

现在,我的问题与with问题有关-有没有办法将这些关系的关系添加到我返回的收藏夹中?

例如:

Load模型中,我与shipment具有以下关系:

public function shipment(){
    return $this->belongsTo(shipment::class, 'shipmentID');
}

shipment模型中,我具有以下关系:

public function shiptoAccount(){
    return $this->belongsTo('App\Customer', 'ship_to');
}

是否有一种方法可以包含与Loads集合关联的shipment的shiptoAccount返回?

1 个答案:

答案 0 :(得分:1)

使用“点”语法(documentation):

$scheduleLoads = Load::with('shipment.shiptoAccount', 'driver', 'tractor');