How to increment column value of table in Laravel

Created 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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.