Laravel:如何从表中获取特定记录及其数据透视表

时间:2018-08-29 12:17:34

标签: laravel-5.6

让我说我的表结构如下

  

商店

– id

–名称

  

产品

– id

–名称

  

product_shop

– product_id

– shop_id

– product_price

建立关系船

  

在商店模式中

我正在建立关系

  

公共功能产品()

     

{

     

返回$ this-> belongsToMany('App \ Product');

     

}

.......

  

在产品模式中

我正在建立关系Ship

  

公共功能Shops()

     

{

     

返回$ this-> belongsToMany('App \ Shop');

     

}

现在,我想从我有产品$ id = 5的数据透视表中获取产品价格;

  

Shop :: find($ id)-> withPivot-> product_price;

0 个答案:

没有答案