PHPackages                             cleaniquecoders/inviteable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. cleaniquecoders/inviteable

AbandonedLibrary[Authentication &amp; Authorization](/categories/authentication)

cleaniquecoders/inviteable
==========================

Built with Laravel Standalone Package Creator

v2.0.0(5y ago)3291[1 issues](https://github.com/cleaniquecoders/inviteable/issues)MITPHPPHP &gt;=7.3CI failing

Since Jan 30Pushed 1mo agoCompare

[ Source](https://github.com/cleaniquecoders/inviteable)[ Packagist](https://packagist.org/packages/cleaniquecoders/inviteable)[ RSS](/packages/cleaniquecoders-inviteable/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (6)Dependencies (5)Versions (15)Used By (0)

[![Build Status](https://camo.githubusercontent.com/6ae2fc73e8280c8cba24969638362f1d91f3a263f609e457b8606fc151f9cc82/68747470733a2f2f7472617669732d63692e6f72672f636c65616e69717565636f646572732f696e7669746561626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/cleaniquecoders/inviteable) [![Latest Stable Version](https://camo.githubusercontent.com/981088b1917ec259720fa42f6add731742c3970c2e82ba0154496622ed5d1c3f/68747470733a2f2f706f7365722e707567782e6f72672f636c65616e69717565636f646572732f696e7669746561626c652f762f737461626c65)](https://packagist.org/packages/cleaniquecoders/inviteable) [![Total Downloads](https://camo.githubusercontent.com/0c0ff24aae31d3b4fc0593acec1c9cca3170661a69f4508ec1dbf4737bcfb440/68747470733a2f2f706f7365722e707567782e6f72672f636c65616e69717565636f646572732f696e7669746561626c652f646f776e6c6f616473)](https://packagist.org/packages/cleaniquecoders/inviteable) [![License](https://camo.githubusercontent.com/43cc914b6d3e2e6506533ffef20c4185355d3ae2545e271794b4f5ec08377810/68747470733a2f2f706f7365722e707567782e6f72672f636c65616e69717565636f646572732f696e7669746561626c652f6c6963656e7365)](https://packagist.org/packages/cleaniquecoders/inviteable)

About Your Package
------------------

[](#about-your-package)

Inviteable, inspired from [Laravel Auth Invitations](https://github.com/LaravelDaily/Laravel-Auth-Invitations), but in this package, not for Auth, but for anything. Yes, we mean anything! Invitation to group, to class room, to meeting. Can be anything!

Installation
------------

[](#installation)

1. In order to install `cleaniquecoders/inviteable` in your Laravel project, just run the *composer require* command from your terminal:

```
$ composer require cleaniquecoders/inviteable

```

2. Then in your `config/app.php` add the following to the providers array:

```
CleaniqueCoders\Inviteable\InviteableServiceProvider::class,
```

3. Run the migration file:

```
$ php artisan migrate

```

Usage
-----

[](#usage)

Inviteable provide a trait `\CleaniqueCoders\Inviteable\Traits\HasInviteable`.

Following are the sample usage.

### Setup

[](#setup)

```
use CleaniqueCoders\Inviteable\Traits\HasInviteable;

class User extends Authenticatable
{
	use HasInviteable;
}
```

### Creating Invitation

[](#creating-invitation)

```
$invitation = User::create([
    'email'    => 'test@test.com',
    'name'     => 'Test Name',
    'password' => bcrypt('secret'),
])
    ->invitations()
    ->create([
        'name'       => 'Invitation',
        'token'      => str_random(64),
        'invited_by' => 1,
        'is_expired' => false,
        'expired_at' => \Carbon\Carbon::now()->addHours(24),
    ]);

```

Once you have create the invitation, you may use the invitation with events and notifications.

Will add dispatching event on invitation created, so you can extend the use of the invitation to something else like notification.

More sample usage using `routes/console.php`:

```
use App\User;

Artisan::command('invite', function() {
    // create a user that will invite other person
    $invitor = factory(User::class)->create();

    // to invite who
    $to_invite = factory(User::class)->create();

    // login using invitor
    auth()->loginUsingId($invitor->id);

    // invite user to a class
    $to_invite->invitations()->create([
        'name'       => 'Live Coding Class',
        'token'      => str_random(64),
        'invited_by' => auth()->user()->id,
        'is_expired' => false,
        'expired_at' => \Carbon\Carbon::now()->addHours(24),
    ]);
})->describe('Inivite the fastest way via cli.');
```

### Event and Listener

[](#event-and-listener)

1. On Invitation Created - `\CleaniqueCoders\Inviteable\Events\InvitationAccepted`
2. On Invitation Accepted - `\CleaniqueCoders\Inviteable\Events\InvitationAlreadyAccepted`
3. On Invitation Already Accepted - `\CleaniqueCoders\Inviteable\Events\InvitationCreated`

Added Listener to send out e-mail invitation:

1. `CleaniqueCoders\Inviteable\Listeners\Invitations` - You need to configure in your `app/Providers/EventServiceProvider` to have this in your app.

```
/**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        '\CleaniqueCoders\Inviteable\Events\InvitationCreated' => [
            '\CleaniqueCoders\Inviteable\Listeners\Invitations\SendInvitationEmail',
        ],
    ];
```

### Middleware

[](#middleware)

Added Middleware to be use to check only active invite able to get through

```
'inviteable' => \CleaniqueCoders\Inviteable\Http\Middleware\Inviteable::class,
```

### Configuration

[](#configuration)

Added `config/inviteable.php` to handle redirection - using route name:

```
