DEV Community

Yasser Elgammal
Yasser Elgammal

Posted on

Introducing Laravel Easy Wallet Package

Laravel Easy Wallet is a simple and extensible wallet system for Laravel applications. It allows you to associate wallets with any model, manage balances, and record transactions with support for credit and debit.

🚀 Features

  • Attach a wallet to any Eloquent model (walletable)
  • Automatically create a wallet if it doesn’t exist
  • Credit and debit balance safely inside a DB transaction
  • Transaction history tracking

📦 Installation

composer require yasser-elgammal/laravel-easy-wallet
Enter fullscreen mode Exit fullscreen mode

💸 Usage Example

1. Add Required Relation to related models

use YasserElgammal\LaravelEasyWallet\Models\Wallet;

    public function wallet()
    {
        return $this->morphOne(Wallet::class, 'walletable');
    }
Enter fullscreen mode Exit fullscreen mode

2. Credit Wallet

use YasserElgammal\LaravelEasyWallet\Facades\EasyWallet;
use App\Models\User;

$user = User::find(1);

EasyWallet::credit($user, 100.00, 'Initial deposit');
Enter fullscreen mode Exit fullscreen mode

3. Debit Wallet

EasyWallet::debit($user, 25.00, 'Purchased course');
Enter fullscreen mode Exit fullscreen mode

4. Transfer Between Wallets

$fromUser = User::find(1);
$toUser = User::find(2);

EasyWallet::transfer($fromUser, $toUser, 40.00, 'Transfer to friend');
Enter fullscreen mode Exit fullscreen mode

5. Get Wallet Balance

$balance = EasyWallet::balance($user);

Enter fullscreen mode Exit fullscreen mode

📌 Why I Built It

I’ve worked on several projects that needed internal balance logic. Each time, I had to rewrite the same concepts. This package is my way of solving that once and for all — for myself and for the community.


📥 Contributions & Feedback

I’d love your feedback! If you find this package useful or have suggestions, feel free to open an issue or PR on GitHub.

GitHub: github.com/yasser-elgammal/laravel-easy-wallet

Top comments (0)