arsamme / laravel-wallet
Virtual wallet implementation to use in Laravel projects.
v2.0.3
2025-07-29 09:06 UTC
Requires
- php: ^8.2
- ext-json: *
- ext-pdo: *
- brick/math: ~0.10
- illuminate/contracts: ^10.0|^11.0|^12.0
- illuminate/database: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/framework: ^10.0|^11.0|^12.0
- laravel/pint: ^1.22
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^10.0
- phpunit/phpunit: ^11.0
- dev-main
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.5.0
- v1.4.7
- v1.4.6
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/github_actions/actions/checkout-5
- dev-dependabot/npm_and_yarn/vitepress-1.6.4
This package is auto-updated.
Last update: 2025-08-12 22:13:37 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 AliRaghebi\Wallet\Traits\HasWallet; use AliRaghebi\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 AliRaghebi\Wallet\Traits\HasWallet; use AliRaghebi\Wallet\Traits\HasWallet; use AliRaghebi\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!