blackcup/invites

创建邀请的包

0.1.0 2020-03-06 15:44 UTC

README

Latest Version on Packagist Total Downloads

此包允许您发送自定义邀请。一旦发送邀请,收件人将收到一条通知,可以选择接受或拒绝邀请。当收件人接受或拒绝邀请时,发送者将收到通知。每个邀请都有一个专门的类来定制发送、接受或拒绝邀请时应执行的操作。

安装

通过Composer

composer require blackcup/invites

该包将自动注册自己。使用以下命令运行提供的迁移

php artisan migrate

示例用法

通过运行以下命令创建一个新的MakeAdminInvite

php artisan make:invite MakeAdminInvite

这将在app\Invites中创建一个新的类。按照以下方式更改代码

<?php

namespace App\Invites;

use BlackCup\Invites\Invite;
use Illuminate\Support\Facades\Auth;

class MakeAdminInvite extends Invite
{
    /**
     * Indicates if accepting the Invite can only be done by an authenticated user.
     *
     * @var bool
     */
    protected $accept_requires_authentication = true;

    /**
     * Execute Invite specific code on accept.
     *
     * @return void
     */
    public function accept()
    {
        $user = Auth::user();
        $user->admin = true;
        $user->save();
    }
}

一旦收件人接受了此邀请,当前用户的admin字段将被设置为true

接下来,我们可以使用以下方式发送邀请

$invite = new MakeAdminInvite();
Invites::send($invite, 'We would like to make you admin to our awesome site', 'James Recipient', 'recipient@example.com', 'John Sender', 'sender@example.com');

资源

可以使用以下方式发布包资源

php artisan vendor:publish --provider="BlackCup\Invites\InvitesServiceProvider" [--tag="..."]

(可能的标签是configviewslang)

定制

如果您不想使用默认的路由,请在config/invites.php中将布尔值routes设置为false

在您的自定义邀请类中,您可以覆盖多个受保护属性以改变邀请的行为

您可以在邀请过程中几个步骤发送通知。将属性设置为null以完全禁用通知。

/**
 * The Notification to send to the recipient of the invite.
 *
 * @var string|null Notification class
 */
protected $received_notification = InvitedNotification::class;

/**
 * The Notification to send to the sender when the invite has been accepted.
 *
 * @var string|null Notification class
 */
protected $accepted_notification = InviteAcceptedNotification::class;

/**
 * The Notification to send to the sender when the invite has been rejected.
 *
 * @var string|null Notification class
 */
protected $rejected_notification = InviteRejectedNotification::class;

为了要求用户在接受或拒绝邀请之前先进行身份验证,覆盖以下属性

/**
 * Indicates if accepting the Invite can only be done by an authenticated user.
 *
 * @var bool
 */
protected $accept_requires_authentication = true;

/**
 * Indicates if rejecting the Invite can only be done by an authenticated user.
 *
 * @var bool
 */
protected $reject_requires_authentication = true;

为了设置描述您的邀请的通用文本

/**
 * Description of the invite.
 *
 * @var string|null
 */
protected $description = '...';

变更日志

请参阅变更日志以获取有关最近更改的更多信息。

测试

vendor/bin/phpunit

贡献

请参阅contributing.md以获取详细信息及待办事项列表。

安全

如果您发现任何安全相关的问题,请通过电子邮件info@blackcup.nl联系,而不是使用问题跟踪器。

鸣谢

许可

MIT。有关更多信息,请参阅许可文件