Answer the question
In order to leave comments, you need to log in
How to do multiple UPDATE using Query Builder?
Hello!
Does anyone know how to do multiple UPDATE?
Right now I'm doing this:
foreach ($users as $u) {
$update = DB::update('users_table');
$update->set(array('rank' => DB::expr('rank + ' . $u['rank'])))
->where('id', '=', $u['id']);
$update->execute();
}
Answer the question
In order to leave comments, you need to log in
If the changes are by the same number, then it’s just worth using whereIn, if it’s different, then you should leave it like that. In sql, this is done through constructs like
In a loop, the request is clearer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question