dongpa6867
2019-02-21 14:55
浏览 460
已采纳

Laravel 5.7雄辩地更新/删除多条记录

My table structure is like this:

invoices: 

        id, title, desciption, total_amount, --

products: 

        id, name, price, --

invoice_products

        id, invoice_id, product_id, --
  • One invoice can have multiple products, so,

  • I created an invoice with products, then data fills according to above DB structure.

  • When i update invoice (let say invoice_id = 2 ), then, i am confused what is the best way to update "invoice_products" table.

  • My approach is ( for "invoice_products" table):

    • delete * from invoice_products where invoice_id=2;
    • then insert modified products again.
  • I think this is not good approach, as i am force deleting the rows in "invoice_products" and again inserting new updated products.

  • is there any way to do via eloquent ?

图片转代码服务由CSDN问答提供 功能建议

我的表格结构如下:</ p>

 发票:\  n 
 id,title,desciption,total_amount, -  
 
产品:
 
 id,name,price, -  
 
invoice_products 
 
 id,invoice_id,product_id, -  
 </ 代码> </ pre> 
 
 
  • 一张发票可以有多个产品,所以,</ p> </ li>

  • 我创建了发票 使用产品,然后根据上述DB结构填充数据。 </ p> </ li>

  • 当我更新发票(比方说invoice_id = 2)时,我很困惑更新“invoice_products”表的最佳方法是什么。</ p> < / li>

  • 我的方法是(对于“invoice_products”表):</ p>

    • 从invoice_products中删除*,其中invoice_id = 2; </ li>
    • 然后再次插入修改后的产品。</ li> </ ul> </ li>
    • 我认为这不是好方法,因为我强行删除 “invoice_products”中的行,并再次插入新的更新产品。 </ p> </ li>

    • 有没有办法通过口才?</ p> </ li> </ ul> </ div>

2条回答 默认 最新

相关推荐 更多相似问题