Skip to content

Latest commit

 

History

History
executable file
·
81 lines (61 loc) · 1.37 KB

README.md

File metadata and controls

executable file
·
81 lines (61 loc) · 1.37 KB

Laravel Inviteable

Installation

First, pull in the package through Composer.

composer require tshafer/laravel-inviteable:1.0.*@dev

And then include the service provider within app/config/app.php.

'providers' => [
    Tshafer\Inviteable\ServiceProvider::class
];

At last you need to publish and run the migration.

php artisan vendor:publish --provider="Tshafer\Inviteable\ServiceProvider" && php artisan migrate

Setup a Model

<?php

namespace App;

use Tshafer\Inviteable\Contracts\Inviteable;
use Tshafer\Inviteable\Traits\Inviteable as InviteableTrait;
use Illuminate\Database\Eloquent\Model;

class User extends Model implements Inviteable
{
    use InviteableTrait;
}

Examples

Generate a new invitation code

Invite::getNewCode([
    'email' => 'test@test.io',
]);

Find an invitation by code

Invite::getInviteByCode($invite->code);

Find a valid invitation by code

Invite::getValidInviteByCode($invite->code);

Claim an invitation

$invite->claim($user);

Check if an invitiation has already been claimed

if ($invite->claimed()) {
    dd('This invite has already been claimed.');
}

Access the model that claimed the invite

dump($invite->claimer);

Access the invite that has been claimed by a model

dump($user->invite);