Laravel数据透视表引用了两个以上的表?

时间:2014-01-27 05:37:00

标签: php laravel many-to-many pivot-table

有点难以解释,但我会尽力在这里:

Supplier
  id
  name
Product
  id
  name
Delivery_Method
  id
  name
Supplier_Product --pivot table
  id
  supplier_id
  product_id
  delivery_method_id
  delivery_time

我的SupplierProduct表都是模型,但交付方法不是。我知道如何在Product::with('suppliers')->get()模型中使用pivot来通过此函数调用Product之类的内容:

public function suppliers()
{
  return $this->belongsToMany('Supplier')->withPivot('delivery_time');
}

虽然这很好但我仍然没有得到delivery_method,因为我不知道如何加入delivery_method_id来获取它的名字。我怎样才能做到这一点?

请注意,delivery_method没有型号。

0 个答案:

没有答案