bavix / laravel-wallet

It's easy to work with a virtual wallet
https://bavix.github.io/laravel-wallet/
MIT License
1.12k stars 224 forks source link

Check balance issue #984

Closed Basheer21 closed 1 month ago

Basheer21 commented 1 month ago

The balance attribute in the modelInstance is returning 0 when accessed via modelInstance->balance, even though querying the associated Wallet model directly returns the correct balance

To Reproduce Steps to reproduce the behavior:

  1. create a wallet for the modelInstance ex: $business->createWallet([ 'name' => $business->name . ' Wallet', 'slug' => 'business-wallet', ]);

  2. make deposit $business->getWallet('business-wallet')->deposit(100000); // pls note if i do $business->deposit(100000); without specifying the walletName its gonna create another wallet

  3. check balance: $business->balance will retrieve 0 while if I check the balance using the wallet Model will bring the correct balance ex/ $wallet = Wallet::where('holder_id', 2)->get();

Expected behavior $business->balance : should retrieve the correct balance

rez1dent3 commented 1 month ago

Hello.

$business->balance : should retrieve the correct balance

This is an appeal to the default wallet, and you are replenishing a multi-wallet.

If you want to get his balance, the code should be like this:

$business->getWallet('business-wallet')->balance;
rez1dent3 commented 1 month ago

Multi-wallets: https://bavix.github.io/laravel-wallet/guide/multi/new-wallet.html#how-to-get-the-right-wallet

Single wallet: https://bavix.github.io/laravel-wallet/guide/single/deposit.html#make-a-deposit

rez1dent3 commented 1 month ago

If you need multi-wallets and do not need the default wallet, then disable it leaving only the HasWallets trait.

That is, remove HasWalletFloat or HasWallet.

Basheer21 commented 1 month ago

Thanks a lot for your fast support.