Get the App
SLTechnology News&Howtos  ›  Development  › 

How to increase and decrease in Laravel Eloquent

Shulou Source: shulou.com Published: 2022-06-01 04:35:29 10月02日 Update

This article mainly introduces how to achieve increasing and decreasing Laravel Eloquent, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Increasing and decreasing

To replace the following implementation:

$article = Article::find ($article_id); $article- > read_count++;$article- > save ()

You can do this:

$article = Article::find ($article_id); $article- > increment ('read_count')

The following methods can also be implemented:

Article::find ($article_id)-> increment ('read_count'); Article::find ($article_id)-> increment (' read_count', 10); / / + 10Product::find ($produce_id)-> decrement ('stock') / /-1 Thank you for reading this article carefully. I hope the article "how to increase and decrease Laravel Eloquent" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles values interests at the same time methods more friends knowledge editing industry information information channels channels reference learning help support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Docker Huawei OPPO Reno Shulou Information