anexponent/tgr-laravel-wallet

A modern Laravel package providing a simple virtual wallet system.

Installs: 37

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

pkg:composer/anexponent/tgr-laravel-wallet

v1.1.0 2025-11-11 03:54 UTC

This package is auto-updated.

Last update: 2025-12-11 04:33:01 UTC


README

A modern, simple, and flexible virtual wallet system for Laravel.

This package allows you to attach a wallet to any model (usually a User), deposit and withdraw credits, and keep a full transaction history. Ideal for apps where users buy credits or virtual currency to spend on services or goods.

Features

Assign a wallet to any model (User, Member, etc.) Track deposits, withdrawals, refunds, and custom transaction types Transaction metadata for payment references or descriptions Safe balance updates using database transactions Force withdrawals or failed deposits Configurable models for Wallet, Transaction, and User Supports Laravel 9, 10, and 11

Installation

Install the package with composer:

composer require anexponent/tgr-laravel-wallet

The package automatically merges default configuration, so you can start using it immediately.

Run Migrations

php artisan migrate

Publish the migrations with this artisan command:

Optional: You can publish the migrations if you want to customize them:

php artisan vendor:publish --provider="Anexponent\Wallet\WalletServiceProvider" --tag=migrations

Configuration

Default configuration is already merged automatically. The defaults are:

    return [
        'user_model' => App\Models\User::class,
        'wallet_model' => Anexponent\Wallet\Wallet::class,
        'transaction_model' => Anexponent\Wallet\Transaction::class,
    ];

Optional: You can publish the config to customize it:

php artisan vendor:publish --provider="Anexponent\Wallet\WalletServiceProvider" --tag=config

This will merge the config.php config file where you can specify the Users, Wallets & Transactions classes if you have custom ones.

Usage

Add the HasWallet trait to your User model.

use Anexponent\Wallet\HasWallet;

class User extends Model
{
    use HasWallet;

    ...
}

At some point before making transactions, create the user's wallet.

$user->wallet()->firstOrCreate([]);

Then you can easily make transactions from your user model.

$user = User::find(1);
$user->balance; // 0

$user->deposit(100);
$user->balance; // 100

$user->withdraw(50);
$user->balance; // 50

$user->forceWithdraw(200);
$user->balance; // -150

You can easily add meta information to the transactions to suit your needs.

$user = User::find(1);
$user->deposit(100, 'deposit', ['stripe_source' => 'ch_BEV2Iih1yzbf4G3HNsfOQ07h', 'description' => 'Deposit of 100 credits from Stripe Payment']);
$user->withdraw(10, 'withdraw', ['description' => 'Purchase of Item #1234']);

Transactions

Retrieve all transactions:

$transactions = $user->transactions;

Get signed amount

$transaction->signed_amount;

Each transaction includes: amount type accepted meta (array) balance (after transaction) hash (unique ID)

Security

If you discover any security related issues, please email simon@webartisan.be instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.