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
💸 Usage Example
1. Add Required Relation to related models
use YasserElgammal\LaravelEasyWallet\Models\Wallet;
public function wallet()
{
return $this->morphOne(Wallet::class, 'walletable');
}
2. Credit Wallet
use YasserElgammal\LaravelEasyWallet\Facades\EasyWallet;
use App\Models\User;
$user = User::find(1);
EasyWallet::credit($user, 100.00, 'Initial deposit');
3. Debit Wallet
EasyWallet::debit($user, 25.00, 'Purchased course');
4. Transfer Between Wallets
$fromUser = User::find(1);
$toUser = User::find(2);
EasyWallet::transfer($fromUser, $toUser, 40.00, 'Transfer to friend');
5. Get Wallet Balance
$balance = EasyWallet::balance($user);
📌 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.
Top comments (0)