本文介绍了Laravel查询生成器的增量更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要解决我的查询,在这里我需要增加产品数量来更新我的产品数量,这是我的示例代码.

Hi I need to fix my query where I will need to update my product quantity with just incrementing it, here is my code with sample.

    DB::table('product_warehouse')
    ->where('product_id', $product_id)
    ->where('warehouse_id', $warehouse_id)
    ->update(['product_qty' => $old_qty+$product_qty]);

推荐答案

您可以尝试两种方式:

DB::table('product_warehouse')
    ->where('product_id', $product_id)
    ->where('warehouse_id', $warehouse_id)
    ->update(['product_qty' => DB::raw('product_qty + ' . $product_qty)]);

DB::table('product_warehouse')
    ->where('product_id', $product_id)
    ->where('warehouse_id', $warehouse_id)
    ->increment('product_qty', $product_qty);

这篇关于Laravel查询生成器的增量更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 04:23
查看更多