2017-08-30 67 views
0

嗨我需要修復我的查詢,我將需要更新我的產品數量,只是增加它,這裏是我的代碼與示例。Laravel查詢生成器更新與增量

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

回答

2

您可以嘗試兩種方式:

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); 
+1

第二屆一個工作的感謝 –