I need to calculate a columns value based on another columns value from the same table and can't find a how to in the documentation. My code is as follows:
$toChange = json_decode($request->toSend);
$database = $request->user()->id + 1;
Config::set('database.connections.usertable.database','usertable' . $database );
$insert = new Products();
foreach ($request->countries as $key => $value) {
if ($value === true) {
foreach ($toChange as $change) {
$insert->setTable($key . '_products');
$insert->whereBetween('price',[$change->priceRangeFrom,$change->priceRangeTo])->update([
'ip_address' => $request->getClientIp(),
'opt_active' => 1,
// next line is the problem
'price' => 'price' / 100 * (100 - $change->minPrice)
]);
}
}
}
I update a few thousand entries with that and need to get the value from the price field from every column and calculate the new price from it. Can someone advise how to do so?
The query should be like this pdo query
$stmt = $pdo->prepare("UPDATE uk_products SET min_price = (price * ((100 - :min) / 100)) /* ... */ WHERE price BETWEEN :minrange AND :maxrange");
$stmt->execute([':min' => $data['min'] /* ... */ ]);
where this is the calculation in question
min_price = (price * ((100 - :min) / 100))