Friday, 9 July 2021

Laravel Eloquent how to use increment to increment column value

https://laravel.com/docs/5.7/queries#increment-and-decrement

 DB::table('users')->increment('votes');


DB::table('users')->increment('votes', 5);

DB::table('users')->decrement('votes');

DB::table('users')->decrement('votes', 5);

https://stackoverflow.com/questions/37666135/how-to-increment-and-update-column-in-one-eloquent-query
Product::where('product_id', $product->id)
    ->update([
      'count'=> DB::raw('count+1'), 
      'last_count_increased_at' => Carbon::now()
    ]);

No comments:

Post a Comment