laravel update increment code example

Example 1: increment single column laravel

Product::increment('count' , 5); // count + 5

Product::decrement('count', 5); // count - 5

---------------Or-----------------------
  
Product::where('product_id', $product->id)
    ->update([
      'count'=> DB::raw('count+1'), 
      'last_count_increased_at' => Carbon::now()
    ]);

Example 2: laravel eloquent increment

Customer::find($customer_id)->increment('loyalty_points');
  
  
// increment by 20 
  Customer::find($customer_id)->increment('loyalty_points',20);

Tags:

Php Example