I have written a method to update a json string in my database with translations. Some categories have ~300.000 products that need to be updated.
This is my method:
public function generateDutchAttributes(Category $category)
{
$category->products()->chunk(100, function ($products) {
foreach ($products as $product) {
$attributesArray = [];
foreach ($product->attributes as $attribute) {
$attributesArray[Translation::translateNL($attribute['attribute'])] = Translation::translateNL($attribute['value']);
}
//dd($attributesArray);
$product->update(['dutch_attributes' => $attributesArray]);
}
});
return redirect()->route('backend.import');
}
}
After ~10.000 rows, I get a HTTP 500 error because too much memory was used.