minutemailer/laravel-honeypot
Composer 安装命令:
composer require minutemailer/laravel-honeypot
包简介
Flexible credits for Laravel
README 文档
README
Honeypot is a simple credit system for Laravel. With Honeypot, users can have credit buckets where credits can be deposited to or withdrawn from. It's perfect for creating simple virtual currency systems or implementing reward programs.
With Honeypot, you can easily manage credits for your users and keep track of all transactions. Whether you're building an e-commerce platform or a social network, Honeypot makes it easy to add a credit system to your Laravel application.
Installation
You can install the package via composer:
composer require minutemailer/laravel-honeypot
The HoneypotServiceProvider will be auto-discovered and registered by Laravel.
Next, create and run the database migration:
php artisan honeypot:migration:make php artisan migrate
Finally add the CanHaveCredits trait to your User model:
use Minutemailer\Honeypot\Traits\CanHaveCredits; class User extends Authenticatable { use CanHaveCredits; }
Usage
In Honeypot, credit buckets must have a name, but you can also choose to set an expiration date for each bucket. If no expiration date is set, the bucket will remain active indefinitely. Additionally, you have the option to set a validity date for each bucket.
Creating a bucket
To create a bucket, use the addCreditBucket method on the User model:
$user->addCreditBucket('credits', [ 'expires_at' => now()->addYear(), // Optional, defaults to null 'valid_from' => now()->subYear(), // Optional, defaults to null 'amount' => 1000 // Optional, defaults to 0 ]);
The name is unique for each user, so you can't create two buckets with the same name for the same user.
Depositing credits
To deposit credits to a bucket, you need to select the bucket by name and then call the add method on the bucket:
$user->getCreditBucket('credits')->add(100);
Using credits
Same as depositing, but use the use method instead:
$user->getCreditBucket('credits')->use(100);
Using credits will increment the used column on the bucket and keep the amount column intact.
Default bucket
Depending on your application, you might want to utilize the default bucket. You might only have one type of credits but multiple types of buckets. Say for example earned credits and bought credits. The default bucket is the bucket with the shortest expiration date. This helps the user to use the credits that are about to expire first.
Therefor, you could use this logic to dynamically withdraw credits from the user:
$creditsToWithdraw = 100; while ($creditsToWithdraw > 0) { $bucket = $user->getDefaultCreditBucket(); if ($bucket->amount > $creditsToWithdraw) { $bucket->use($creditsToWithdraw); $creditsToWithdraw = 0; } else { $creditsToWithdraw -= $bucket->amount; $bucket->use($bucket->amount); } }
minutemailer/laravel-honeypot 适用场景与选型建议
minutemailer/laravel-honeypot 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.1k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「credits」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 minutemailer/laravel-honeypot 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 minutemailer/laravel-honeypot 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 minutemailer/laravel-honeypot 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
It's easy to work with a virtual wallet.
Alfabank REST API integration
Easy to use virtual wallet for your app
A modern Laravel package providing a simple virtual wallet system.
A simple starter framework for implementing credits/accounts with Craft Commerce.
Easy work with virtual wallet.
统计信息
- 总下载量: 8.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-08