When there is enough money in the account, you can transfer/withdraw it or buy something in the system.
Since the currency is virtual, you can buy any services on your website. For example, priority in search results.
Find user:
$user = User::first();
As the user uses HasWallet, he will have balance property.
Check the user's balance.
$user->balance; // 100
$user->balanceInt; // 100
The balance is not empty, so you can withdraw funds.
$user->withdraw(10);
$user->balance; // 90
$user->balanceInt; // 90
It's simple!
Forced withdrawal is necessary for those cases when the user has no funds. For example, a fine for spam.
$user->balance; // 100
$user->balanceInt; // 100
$user->forceWithdraw(101);
$user->balance; // -1
$user->balanceInt; // -1
There can be two situations:
Zotel\Wallet\Exceptions\BalanceIsEmptyZotel\Wallet\Exceptions\InsufficientFundsHow can I help you explore Laravel packages today?