jhacobs / laravel-invites
邀请用户加入您的 Laravel 应用程序
v1.0.0
2021-01-30 01:29 UTC
Requires
- php: ^7.2|^8.0
- illuminate/database: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^6.9
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-18 22:41:13 UTC
README
邀请用户加入您的应用程序
安装
您可以通过 composer 安装此包
composer require jhacobs/laravel-invites
发布邀请配置文件
php artisan vendor:publish --provider="Invites\InviteServiceProvider" --tag=config
发布迁移
php artisan vendor:publish --provider="Invites\InviteServiceProvider" --tag=migrations
现在运行 php artisan migrate
创建邀请表。
用法
准备您的模型
将 CanBeInvited 接口添加到您的用户模型中
use Jhacobs\Invites\Contracts\CanBeInvited; class User extends Authenticatable implements CanBeInvited
实现 getEmailForInvites 方法,以便包知道哪个字段包含用户的电子邮件。
public function sendInviteNotification(string $token) { return 'email'; }
实现 sendInviteNotification 方法,以便向用户发送邀请通知。
public function sendInviteNotification(string $token) { $this->notify(new InviteUserNotification($token)); }
发送邀请通知
要发送邀请通知,请调用 Invite 门面上的 sendInviteLink 方法。
use Jhacobs\Invites\Facades\Invite; use App\Models\User; $user = User::find(1); Invite::sendInviteLink($user);
创建用户的密码
要创建用户的密码,请调用 Invite 门面上的 createPassword 方法。
您必须传递用户的电子邮件、sendInviteLink 方法创建的未哈希令牌以及用户的新密码。
use Jhacobs\Invites\Facades\Invite; Invite::createPassword($request->get('email'), $request->get('token'), $request->get('password'), function (User $user, string $password) { $user->password = Hash::make($password); $user->save(); });
许可证
此项目是开源软件,许可协议为MIT 许可证