gpt4 book ai didi

Laravel 查询构建器增量更新

转载 作者:行者123 更新时间:2023-12-02 12:22:18 24 4
gpt4 key购买 nike

您好,我需要修复我的查询,我需要通过增加产品数量来更新产品数量,这是我的代码和示例。

    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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com