How to increment column value of table in Laravel

Updated at 07-Jan-2022, By samar

How to increment column value of table in Laravel

With this article, we’ll look at some examples of how to address the "How to increment column value of table in Laravel" problem.

You can increment the column value of the table in Laravel using increment method. You can increment value by one or you can also increment the value by a specific number
  • Laravel increment table column value using increment() method

    //Increment view_count column value by 1 of posts table
    Post::find(1)->increment('view_count');
    
    //Increment column view_count with a specific value
    User::find(1)->increment('points', 20);
    

    This code snippet is used to increment the value of a specific column of a table. You can increment value by 1 without specifying the value to the second argument of the method and you can also pass the specific number to the second argument of increment method to increase the value to the desire output.

Back to code snippet queries related laravel