currency->accounts; foreach ($accounts as $account) { $initialHistory = $account->histories()->where('account_id', $account->id) ->orderBy('created_at') ->first(); if ($initialHistory) { $originalBalance = $initialHistory->balance; $originalBalance = money($originalBalance, $account->currency->code)->getAmount(); $originalRate = $initialHistory->exchange_rate; $precision = $account->currency->precision; $newRate = $event->currency->rate; $newBalance = ($newRate / $originalRate) * $originalBalance; $newBalanceScaled = round($newBalance, $precision); $account->balance = $newBalanceScaled; $account->save(); } } }); } }