Answer the question
In order to leave comments, you need to log in
Proper MySQL Bulk Update in Laravel?
There are about 10,000 products, you need to update prices by category, for each group of products by category there are certain price increase rates. But is it correct to do the update inside the loop?
There is only one solution that comes to mind right now:
// И так более 10 тысяч запросов за раз
foreach($products as $p) {
Products::where('id', $p->id)->update(['price' => $newPrice]);
}
Answer the question
In order to leave comments, you need to log in
If there are no event hooks associated with these fields, then it's better to do everything through bulk operations (and yes, arbitrary expressions can also be used there )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question