nattaponra / larawallet
v1.2
2018-06-20 09:57 UTC
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~5.7
This package is not auto-updated.
Last update: 2024-09-24 18:32:24 UTC
README
Lara wallet 是一个钱包系统包,允许您在 Laravel 框架中快速开发钱包系统。
特性
- 余额查询
- 存款
- 取款
- 转账
- 费用
- 沙盒模式
1. 安装
使用 composer 安装此包
composer require nattaponra/larawallet
2. 运行迁移
使用以下 artisan 命令发布迁移和配置文件
php artisan vendor:publish --provider="nattaponra\LaraWallet\LaraWalletServiceProvider"
运行迁移文件以创建数据库表
php artisan migrate
3. 使用用户模型使用钱包。
在 User 模型 (app/User.php) 中添加 'HasWallet' 特性。对于沙盒模式,添加 'HasSanBoxWallet' 特性。
class User extends Authenticatable { use HasWallet; use HasSanBoxWallet; ...... }
4. 使用
创建示例用户
$user = Auth::user();
余额查询
echo $user->wallet->balance()
存款
$user->wallet->deposit(100);
取款
$user->wallet->withdraw(5000);
转账
$user1 = User::find(1); $user2 = User::find(2); $user1->wallet->deposit(15000); $user1->wallet->transfer(1000,$user2); echo $user1->wallet->balance(); #14000 echo $user2->wallet->balance(); #1000
沙盒模式
$user->sanBoxWallet->balance();