chapdel/credits
Composer 安装命令:
composer require chapdel/credits
包简介
A credit system for Laravel.
README 文档
README
This is a small package that adds a credit system that you might need for various reasons:
- awarding users based on their activity
- rewards in credits instead of real money
- rewards in credits for referrals
- etc.
Installation
Install the package via composer:
composer require geowrgetudor/laravel-balance
Publish and run the migrations with:
php artisan vendor:publish --tag="balance-migrations"
php artisan migrate
If you decide to change the default migration table name, make sure you publish the config file and change the table name there too:
php artisan vendor:publish --tag="balance-config"
This is the contents of the published config file:
return [ /** * Default table name. * If you have changed the migration, make sure you change this too. */ 'table' => 'balances', 'default_currency' => 'EUR', // Default Currency ];
Prepare your model
Add the HasBalance trait to any model you need to.
use Geow\Balance\Traits\HasBalance; class User extends Model { // ... use HasBalance; }
Usage
// Set balance (similar to increaseCredit() method - just a naming difference) $user->setCredit(2000); // Get balance $user->credit; // Increase balance $user->increaseCredit(1000); // Decrease balance $user->decreaseCredit(500); // Reset balance to 0 $user->resetCredit(); // Check if the user has balance $user->hasCredit(); // Passing a reason for setting/increasing/deacreasing the balance $user->setCredit(20000, 'Signup bonus'); $user->increaseCredit(1000, 'Awarded credits'); $user->decreaseCredit(250, 'Service usage'); // Get balance as currency $user->increaseCredit(1000); $user->credit; // returns 1000 (represeting cents) $user->creditCurrency; // returns $10.00 (representing dollars) // If you need to display using a different currency $user->withCurrency('EUR')->creditCurrency // returns €10.00 // Getting all model related transactions (increases and decresed in balance) $user->credits; // Returns \Illuminate\Database\Eloquent\Collection
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
chapdel/credits 适用场景与选型建议
chapdel/credits 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 256 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「balance」 「credit-system」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chapdel/credits 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chapdel/credits 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chapdel/credits 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A credit system / balance for Laravel.
Maintains a history of balance movements in the eloquent models. This simple package will keep track of the balance of your models. You can increase, decrease, reset and set the balance. It is also possible to check if a model has a positive balance or no balance.
Supports user balance and transactions, calculating actual balance from history
A unified Flarum extension that adds a virtual currency system with full transaction history tracking.
Laravel package that provide account balance and transactions functionality for Laravel 5
Alfabank REST API integration
统计信息
- 总下载量: 256
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-22