abstem/invites
Composer 安装命令:
composer require abstem/invites
包简介
An Invitation-Based Membership System
README 文档
README
Invites provides a way to limit access to your Laravel applications by using invite codes.
Invite Codes:
- Can be available to anyone (great for sharing on social media).
- Can have a limited number of uses or unlimited.
- Can have an expiry date, or never expire.
Installation
You can pull in the package using composer:
$ composer require abstem/invites
Next, register the service provider with Laravel (no need on version 5.5):
// config/app.php 'providers' => [ ... Abstem\Invites\InvitesServiceProvider::class, ];
And, register the facade:
// config/app.php 'aliases' => [ ... 'Invites' => Abstem\Invites\Facades\Invites::class, ];
Finally, migrate the database:
$ php artisan migrate
Usage
Generate Invites
Make a single generic invite code with 1 redemption, and no expiry.
Invites::generate()->make();
Make 5 generic invite codes with 1 redemption each, and no expiry.
Invites::generate()->times(5)->make();
Make an invite with 10 redemptions and no expiry.
Invites::generate()->uses(10)->make();
Make an invite that expires on a specific date.
$date = Carbon::now('UTC')->addDays(7); Invites::generate()->expiresOn($date)->make();
Make an invite that expires in 14 days.
Invites::generate()->expiresIn(14)->make();
Redeem Invites
You can redeem an invite by calling the redeem method. Providing the invite code and optionally an email address.
Invites::redeem('ABCDE');
If invites is able to redeem the invite code it will increment the number of redemptions by 1, otherwise it will throw an exception.
InvalidInviteCodeis thrown if the code does not exist in the database.ExpiredInviteCodeis thrown if an expiry date is set and it is in the past.MaxUsesReachedis thrown if the invite code has already been used the maximum number of times.
All of the above exceptions extend InvitesException so you can catch that exception if your application does not need to do anything specific for the above exceptions.
try { Invites::redeem(request()->get('code'), request()->get('email')); } catch (InvitesException $e) { return response()->json(['error' => $e->getMessage()], 422); }
Check Invites without redeeming them
You can check an invite by calling the check method. Providing the invite code and optionally an email address. (It has the same signature as the redeem method except it will return true or false instead of throwing an exception.
Invites::check('ABCDE');
Change Error Messages (and translation support)
In order to change the error message returned from invites, we need to publish the language files like so:
$ php artisan vendor:publish --tag=translations
The language files will then be in /resources/lang/vendor/invites/en where you can edit the messages.php file, and these messages will be used by invites. You can create support for other languages by creating extra folders with a messages.php file in the /resources/lang/vendor/invites directory such as de where you could place your German translations. Read the localisation docs for more info.
Config - change table name
First publish the package configuration:
$ php artisan vendor:publish --tag=config
In config/invites.php you will see:
return [ 'invite_table_name' => 'invites', ];
If you change the table name and then run your migrations Invites will then use the new table name.
Console
To remove used and expired invites you can use the cleanup command:
$ php artisan invites:cleanup
abstem/invites 适用场景与选型建议
abstem/invites 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 abstem/invites 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 abstem/invites 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-06