我有三个模型:
Product
Inventory
Order
它们之间的关系如下:
Order 与 Inventory 和 $ninventory->belongsTo('product'); 有 manyToMany 关系
/** Product Model **/
class Product extend Model
{
public function inventories()
{
return $this->hasMany('App\Inventory');
}
}
/** Inventory Model **/
class Inventory extend Model
{
public function products()
{
return $this->belongsTo('App\Product');
}
}
/** Order Model **/
class Order extend Model {
public function inventories()
{
return $this->belongsToMany('App\Inventory','order_items');
}
//how do I get this?
public function products()
{
}
}
由于数据透视表,这hasManyThrough
将不起作用。order_items
如何获得订单的产品?