bavix / laravel-wallet

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

How to retrieve "deposit" and/or "withdrawal" transaction history of user's connected ??? #931

Closed chegmarco1989 closed 4 months ago

chegmarco1989 commented 4 months ago

Hello.

How to get transaction history (deposit and/or withdrawal) for a personal Laravel user ??? Because I don't see anywhere on the documentation about how to retrieve transaction history (deposit and/or withdrawal) of user's connected.

PLEASE HELP ME.

rez1dent3 commented 4 months ago

Hello.

$user->transactions() // from all wallets
$user->walletTransactions() // from default wallet
$wallet->walletTransactions() // from current wallet
rez1dent3 commented 4 months ago

I missed the button and didn't notice it right away.

rez1dent3 commented 4 months ago

Apparently, there are no questions. I am closing the issue.

chegmarco1989 commented 4 months ago

Thanks for anwser.

Even if I add in Top of my Controller and/or in my Model this:

use Bavix\Wallet\Models\Wallet;

I got: Undefined method 'walletTransactions'. error by implementing it in my following method:

public function getTransactionHistory() {
        try {
            $user = Auth::user();

            if (!$user) {
                throw new \Exception("User not authenticated", 401);
            }

            $transactionHistory = $user->walletTransactions();

            return response()->json([
                'success' => true,
                'message' => 'Transaction history retrieved successfully',
                'data' => $transactionHistory
            ]);
        } catch (\Exception $e) {
            return response()->json([
                'success' => false,
                'message' => $e->getMessage(),
                'code' => $e->getCode()
            ]);
        }
    }

PLEASE HELP ME.

rez1dent3 commented 4 months ago

@chegmarco1989 I mistyped the second case. It should be like this:

$user->wallet->walletTransactions() // from default wallet
chegmarco1989 commented 4 months ago

Thanks for your feedback