Skip to content

Commit 4ccc561

Browse files
authored
Merge pull request #12 from eyounelson/main
deposit and deduct from the wallet at the database level
2 parents 57cbff8 + ab66d45 commit 4ccc561

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/Traits/HasWallet.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@ public function deposit(int|float $amount): float|int
1212
{
1313
$this->throwExceptionIfAmountIsInvalid($amount);
1414

15-
$balance = $this->wallet_balance ?? 0;
16-
17-
$balance += $amount;
15+
$this->increment('wallet_balance', $amount);
1816

19-
$this->forceFill(['wallet_balance' => $balance])->save();
20-
21-
return $balance;
17+
return $this->wallet_balance;
2218
}
2319

2420
public function withdraw(int|float $amount): float|int
@@ -27,11 +23,9 @@ public function withdraw(int|float $amount): float|int
2723

2824
$this->throwExceptionIfFundIsInsufficient($amount);
2925

30-
$balance = $this->wallet_balance - $amount;
31-
32-
$this->forceFill(['wallet_balance' => $balance])->save();
26+
$this->decrement('wallet_balance', $amount);
3327

34-
return $balance;
28+
return $this->wallet_balance;
3529
}
3630

3731
public function canWithdraw(int|float $amount): bool

0 commit comments

Comments
 (0)