L
L
lolrofl012018-06-07 09:56:21
Laravel
lolrofl01, 2018-06-07 09:56:21

How to update record in laravel with old value?

Hello.
I don’t find anything in the documentation other than banal examples, one that would show how to update a record by adding a new value to it. For example, there is an entry counter 10. I want to add 20 to it so that the total is 30.
If I write:

ModelName::where('id', 1)->update(['counter' => 20)

That is natural, the counter field will take the value 20. And how can I make it add its value to the one I want to add? I hope I expressed myself well, thanks!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-06-07
@lolrofl01

ModelName::where('id', 1)->increment('counter', 20);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question