有点难以解释,但我会尽力在这里:
Supplier
id
name
Product
id
name
Delivery_Method
id
name
Supplier_Product --pivot table
id
supplier_id
product_id
delivery_method_id
delivery_time
我的Supplier
和Product
表都是模型,但交付方法不是。我知道如何在Product::with('suppliers')->get()
模型中使用pivot来通过此函数调用Product
之类的内容:
public function suppliers()
{
return $this->belongsToMany('Supplier')->withPivot('delivery_time');
}
虽然这很好但我仍然没有得到delivery_method
,因为我不知道如何加入delivery_method_id
来获取它的名字。我怎样才能做到这一点?
请注意,delivery_method
没有型号。