johannesschobel / laravel-inviteme
Laravel 邀请包
dev-master
2021-02-11 09:19 UTC
Requires
- php: >=5.5.0
- laravel/framework: >=5.0
This package is not auto-updated.
Last update: 2024-09-20 02:30:52 UTC
README
为 Laravel 应用提供邀请机制。请注意,此包不处理如何将邀请发送给用户(例如,通过电子邮件)。
安装
首先,将相应的行添加到您的 composer 文件
"require" : { ... , "johannesschobel/laravel-inviteme": "dev-master" , }
然后运行 composer install 安装新组件。
然后,将包中的相应 ServiceProvider 添加到您的 config/app.php 配置文件中,如下所示
'providers' => [ ... , JohannesSchobel\InviteMe\InviteMeServiceProvider::class, ],
然后,您只需使用以下命令添加提供的 migration 文件
php artisan vendor:publish --provider="JohannesSchobel\InviteMe\InviteMeServiceProvider" --tag="migrations"
然后使用以下命令迁移您的数据库
php artisan db:migrate
如果您想,可以使用以下命令覆盖此包的基本配置
php artisan vendor:publish --provider="JohannesSchobel\InviteMe\InviteMeServiceProvider" --tag="config"
这将把 inviteme 配置文件复制到您的 config 文件夹。使用此文件,您可以自定义包的各种参数。目前,可用的选项不多,但是我会继续添加更多;)
使用方法
为了创建一个 邀请,您只需创建一个 new InvitationManager()。此类管理所有提供的功能。
可用方法
createInvitation
如果您想为用户创建一个 邀请,请调用此方法。相应的参数是
@param String $email the email this invitation shall be sent (not handled by this package!) @param integer $days amount of days this invitation will be available @param object $model bind this invitation to a specific model @param String $custom custom data for this invitation @return Invitation | null the created invitation
我创建此包的主要目的是,现有的邀请包只为邀请(新)用户到应用程序/平台提供功能。然而,它们不允许邀请用户参与特定的资源。
示例
作为一个编辑,正在处理一个 文档,我想邀请其他 用户 参与我编辑文档。因此,我会使用以下代码创建一个 邀请
// the document I would like to invite other users to. $document = Document::find(1); // get the user that shall be invited $user = User::find(1); $im = new InvitationManager(); $invitation = $im->createInvitation( $user->email, // the email this invitation shall be sent to 10, // the invitation shall be available for 10 days (optional) $document, // the document this user shall be invited to (optional) null // additional information (optional) ); // now do whatever you like with this invitation // this invitation is now bound to this specific resource $document
其他方法相当直观,但我会稍后添加它们的文档,因为我将继续为此包工作。