Laravel Quick DB query building:

How can we increase and decrease in Laravel? Laravel gives us the function to do this fast and effectively. Please follow the below instructions to do this.

  • Increase Value of a numeric column
DB::table('users')->increment('votes'); 
// this will increase vote column by 1

DB::table('users')->increment('votes', 5);
// this will increase vote column by 5
  • Decrease Value of a numeric column
DB::table('users')->decrement('votes');
// this will decrease vote column by 1

DB::table('users')->decrement('votes', 5);
// this will decrease vote column by 5

Leave a Reply

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