定制 hesamrad/laravel-wallet 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hesamrad/laravel-wallet

Composer 安装命令:

composer require hesamrad/laravel-wallet

包简介

A minimalistic wallet for any Laravel application allowing logging and concurrency.

README 文档

README

A minimalistic wallet for any Laravel application; it's easy to install and to work with. It also logs every transaction inside storage for future monitoring.

Installation

Install via Composer:

composer require hesamrad/laravel-wallet

The package will automatically register its service provider.

Configuration

Publish the necessary files:

php artisan vendor:publish --provider="HesamRad\LaravelWallet\LaravelWalletServiceProvider"

This will publish the config, migrations and language files used by the wallet.

Usage

There is not much to do after installing. You only have to add a few lines to your desired model to get started; I presume you have a User model that needs a wallet.

  1. Have the User model implement \HesamRad\LaravelWallet\Contracts\HasWallet interface.
  2. Use the \HesamRad\LaravelWallet\Concerns\InteractsWithWallet trait inside the User model.
use Illuminate\Foundation\Auth\User as Authenticatable;
use HesamRad\LaravelWallet\Contracts\HasWallet;
use HesamRad\LaravelWallet\Concerns\InteractsWithWallet;

class User extends Authenticatable implements HasWallet
{
    use InteractsWithWallet;

    // The resf of the model...
}

This will register neccessary methods and functionalities to work with wallet.

And then run the migtations:

php artisan migrate

And you're done!

How to deposit money into the wallet?

To deposit money into the wallet, call the deposit method on the model:

$user->deposit(
    amount: 1.25, 
    description: 'This is a test.',
    meta: [
        'key' => 'value'
    ]
);

This will deposit 1.25 into the user's wallet and logs the transaction inside wallet_logs table. (Note that the description and meta fields will be stored inside wallet_logs table.)

How to withdraw money from the wallet?

To withdraw money from the wallet, call the withdraw method on the model:

$user->withdraw(
    amount: 1.00, 
    description: 'This is another test.',
    meta: [
        'another-key' => 'another-value'
    ]
);

This will withdraw 1.00 from the user's wallet and logs the transaction inside wallet_logs table. (Note that the description and meta fields will be stored inside wallet_logs table.)

How to get current balance of the wallet?

To get current balance of the wallet, call the balance method on the model:

$user->balance();

How to get wallet logs?

To get wallet logs, call logs relationship on the wallet:

$user->wallet?->logs;

Support

If you encounter any issues, have questions or some idea to improve the package, feel free to create an issue or reach out to me:

  1. Create a new issue
  2. Email me

License

This package is open-source software licensed under the MIT license.

Credits

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固