Reputation: 3002
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]);
Upvotes: 3
Views: 6079
Reputation: 393
You can try both ways:
DB::table('product_warehouse')
->where('product_id', $product_id)
->where('warehouse_id', $warehouse_id)
->update(['product_qty' => DB::raw('product_qty + ' . $product_qty)]);
Or
DB::table('product_warehouse')
->where('product_id', $product_id)
->where('warehouse_id', $warehouse_id)
->increment('product_qty', $product_qty);
Upvotes: 9