This is the query i am using:
$number = DB::table('products')->where('id', '=', $product->id)->update(['quantity' => 'quantity', '-', 1 ]);
Please help me with the right syntax. I want to subtract 1 from the current value of quantity column. Thanks
You may use decrement method for this;
The query builder also provides convenient methods for incrementing or decrementing the value of a given column. This is a shortcut, providing a more expressive and terse interface compared to manually writing the update statement.
DB::table('products')->where('id', $product->id)->decrement('quantity');