如何在with查询中使用Laravel雄辩的父字段

如何在with查询中使用Laravel雄辩的父字段,laravel,Laravel,在这里的$query->where('orders.slot_id','slots.id')我想使用父插槽模型id字段。非静态值 比如$query->where('orders.slot\u id',1) 这不是你处理人际关系的方式。如果在订单表中有slot\u id,请在slot模型中定义关系: [{"id":1,"from_time":"13:00:00","to_time":"14:00:00","customer_cut_off_time":"01:00:00","created_at"

在这里的
$query->where('orders.slot_id','slots.id')我想使用父插槽模型id字段。非静态值
比如
$query->where('orders.slot\u id',1)


这不是你处理人际关系的方式。如果在
订单
表中有
slot\u id
,请在
slot
模型中定义关系:

[{"id":1,"from_time":"13:00:00","to_time":"14:00:00","customer_cut_off_time":"01:00:00","created_at":"2018-02-20 11:05:47","updated_at":"2018-02-21 11:52:02","cook_cut_off_time":"11:00:00","hubs":[{"id":1,"name":"WireCamp Interactive LLP","address":"496, 11th Cross Rd, Jeewan Griha Colony, 2nd Phase, JP Nagar, Bengaluru, Karnataka 560078, India","lat":12.908897,"lng":77.59461,"created_at":"2018-02-20 10:02:04","updated_at":"2018-02-20 10:02:19","pivot":{"slot_id":1,"hub_id":1},"orders":[{"id":2,"customer_id":1,"hub_id":1,"slot_id":1,"total_amount":93.6,"status":1,"created_at":"2018-02-21 09:27:38","updated_at":"2018-02-23 10:32:57"},{"id":4,"customer_id":1,"hub_id":1,"slot_id":1,"total_amount":276.6,"status":1,"created_at":"2018-02-21 13:47:25","updated_at":"2018-02-23 10:33:02"},{"id":5,"customer_id":1,"hub_id":1,"slot_id":2,"total_amount":276.6,"status":0,"created_at":"2018-02-21 13:47:25","updated_at":"2018-02-23 10:12:50"}]},{"id":2,"name":"Les Sagnes","address":"Les Sagnes, 63700 La Crouzille, France","lat":46.1578,"lng":2.754926,"created_at":"2018-02-20 11:25:34","updated_at":"2018-02-20 11:25:34","pivot":{"slot_id":1,"hub_id":2},"orders":[]}]},{"id":2,"from_time":"10:00:00","to_time":"00:00:00","customer_cut_off_time":"10:00:00","created_at":"2018-02-20 11:13:15","updated_at":"2018-02-20 11:13:15","cook_cut_off_time":"00:00:00","hubs":[{"id":1,"name":"WireCamp Interactive LLP","address":"496, 11th Cross Rd, Jeewan Griha Colony, 2nd Phase, JP Nagar, Bengaluru, Karnataka 560078, India","lat":12.908897,"lng":77.59461,"created_at":"2018-02-20 10:02:04","updated_at":"2018-02-20 10:02:19","pivot":{"slot_id":2,"hub_id":1},"orders":[{"id":2,"customer_id":1,"hub_id":1,"slot_id":1,"total_amount":93.6,"status":1,"created_at":"2018-02-21 09:27:38","updated_at":"2018-02-23 10:32:57"},{"id":4,"customer_id":1,"hub_id":1,"slot_id":1,"total_amount":276.6,"status":1,"created_at":"2018-02-21 13:47:25","updated_at":"2018-02-23 10:33:02"},{"id":5,"customer_id":1,"hub_id":1,"slot_id":2,"total_amount":276.6,"status":0,"created_at":"2018-02-21 13:47:25","updated_at":"2018-02-23 10:12:50"}]}]}]
并加载具有以下相关订单的插槽:

public function orders()
{
    return $this->hasMany(Order::class);
}

你是怎么做到的?
public function orders()
{
    return $this->hasMany(Order::class);
}
Slot::with('orders')->get()