Answer the question
In order to leave comments, you need to log in
How to update the collection of models?
Good afternoon. There is a collection of models users
. It is necessary to check the field in each model spent
, and if it is more than 1000, add 1 to it and overwrite this model. I can do it through foreach, but I need it to be beautiful using laravel...
Answer the question
In order to leave comments, you need to log in
User::where('spent', '>', 1000)->increment('spent');
->where('spent', '>', 1000)
->update([
'spent'' => \DB::raw('spent+1')
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question