where('id', $this->account_id)->first(); $currentBalance = $account ? $account->current_balance : 0; $normalBalance = strtolower($account->accountType->normal_balance ?? 'debit'); $transactionType = strtolower($this->type); if ($transactionType === 'debit') { if ($normalBalance === 'debit') { $this->balance = $currentBalance + $this->amount; } else { $this->balance = $currentBalance - $this->amount; } } else { // credit if ($normalBalance === 'credit') { $this->balance = $currentBalance + $this->amount; } else { $this->balance = $currentBalance - $this->amount; } } } }