Answer the question
In order to leave comments, you need to log in
Reduce quantity per request?
There is an array of identifiers and an array of numbers. It is necessary for each record with id from the first array to reduce the value of the count field in the table by the value from the second. i.e.:
$ids = [1, 2, 3];
$values = [5, 7, 10];
The count value of the entry with id 1 is decremented by 5, and so on. Can you please tell me how to implement this in one request in Eloquent, if at all possible
Answer the question
In order to leave comments, you need to log in
Can be done in pure mysql.
(see last paragraph)
("Updating a record with a conditional selection in one query")
This issue has already been discussed, because. you have different things, then only the option with CASE in mysql is possible, which is better not to do, you get nonsense like
Foo::whereIn($array1)->update('counter', Db::raw('counter - (CASE WHEN 1 THEN 5.......)'));
Don't skimp on matches.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question