laravel

时间:2017-09-19 10:09:13

标签: php mysql laravel

我是Laravel的新手,我有一个疑问,我有两个表n:n,我想创建一个额外的表来存储每个表的两个ID。如商店和产品。

如何通过在shop_product表中自动创建产品来创建商店?

1 个答案:

答案 0 :(得分:0)

 save shop data      
                 $shop->save();
                 $shopid= $shop->id;
 after save fetch data from shop and simillarly from product

               $product->save();
               $productid= $product->id;
finally use both variables in shop_product like this
             $shop_product->shop_id= $shopid;
               $shop_product->product_id= $productid;