Simple Methods to use increment or decrement a column value in laravel

In this post i show how to Increment or Decrement a column value in laravel.

increment() or decrement() method providing a more expressive and terse interface compared to manually writing the update statement.

In this Method first one argument(Column Name) is mandatory and another one(Value) is Optional.

//stock+1

$singleincrement=Currentstock::find($product_id)->increment('stock');

//stock+50

$incrementstock=Currentstock::find($product_id)->increment('stock', 50);

//stock-50

$reducestock=Currentstock::find($product_id)->decrement('stock', 50);

 

You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *