How to increase and decrease in Laravel Eloquent
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!