您好,我需要修复我的查询,我需要通过增加产品数量来更新产品数量,这是我的代码和示例。
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 查询构建器增量更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45951180/