arsamme/laravel-wallet

Virtual wallet implementation to use in Laravel projects.

v1.4.1 2025-05-05 13:26 UTC

This package is auto-updated.

Last update: 2025-05-06 11:59:10 UTC


README

New Wallet

You can create an unlimited number of wallets, but the slug for each wallet should be unique.

User Model

Add the HasWallet trait's to model.

use ArsamMe\Wallet\Traits\HasWallet;
use ArsamMe\Wallet\Interfaces\Wallet;

class User extends Model
{
    use HasWallet;
}

Create a wallet

Find user:

$user = User::first(); 

Create a new wallet.

$user->hasWallet('my-wallet'); // bool(false)
$wallet = $user->createWallet([
    'name' => 'New Wallet',
    'slug' => 'my-wallet',
]);

$user->hasWallet('my-wallet'); // bool(true)

$wallet->deposit(100);
$wallet->balance; // 100
$wallet->balanceFloatNum; // 1.00

How to get the right wallet?

$myWallet = $user->getWallet('my-wallet');
$myWallet->balance; // 100
$myWallet->balanceFloatNum; // 1.00

Default Wallet + MultiWallet

Is it possible to use the default wallet and multi-wallets at the same time? Yes.

use ArsamMe\Wallet\Traits\HasWallet;
use ArsamMe\Wallet\Traits\HasWallet;
use ArsamMe\Wallet\Interfaces\Wallet;

class User extends Model
{
    use HasWallet, HasWallet;
}

How to get the default wallet?

$wallet = $user->wallet;
$wallet->balance; // 10
$wallet->balanceFloatNum; // 0.10

It's simple!