diff --git a/src/Traits/HasWallet.php b/src/Traits/HasWallet.php index afd6504..3c13ada 100644 --- a/src/Traits/HasWallet.php +++ b/src/Traits/HasWallet.php @@ -12,13 +12,9 @@ public function deposit(int|float $amount): float|int { $this->throwExceptionIfAmountIsInvalid($amount); - $balance = $this->wallet_balance ?? 0; - - $balance += $amount; + $this->increment('wallet_balance', $amount); - $this->forceFill(['wallet_balance' => $balance])->save(); - - return $balance; + return $this->wallet_balance; } public function withdraw(int|float $amount): float|int @@ -27,11 +23,9 @@ public function withdraw(int|float $amount): float|int $this->throwExceptionIfFundIsInsufficient($amount); - $balance = $this->wallet_balance - $amount; - - $this->forceFill(['wallet_balance' => $balance])->save(); + $this->decrement('wallet_balance', $amount); - return $balance; + return $this->wallet_balance; } public function canWithdraw(int|float $amount): bool