PHP code example of offload-project / laravel-invite-only

1. Go to this page and download the library: Download offload-project/laravel-invite-only library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

offload-project / laravel-invite-only example snippets


// Team.php (or any model that can have invitations)
use OffloadProject\InviteOnly\Traits\HasInvitations;

class Team extends Model
{
    use HasInvitations;
}

// User.php
use OffloadProject\InviteOnly\Traits\CanBeInvited;

class User extends Authenticatable
{
    use CanBeInvited;
}

use OffloadProject\InviteOnly\Traits\CanBeInvited;
use OffloadProject\InviteOnly\Traits\HasInvitations;

class User extends Authenticatable
{
    use HasInvitations, CanBeInvited {
        CanBeInvited::acceptedInvitations insteadof HasInvitations;
        HasInvitations::acceptedInvitations as acceptedInvitationsToModel;
    }
}

// Single invitation
$team->invite('[email protected]', [
    'role' => 'member',
    'invited_by' => auth()->user(),
]);

// Bulk invitations
$result = $team->inviteMany(
    ['[email protected]', '[email protected]', '[email protected]'],
    ['role' => 'member', 'invited_by' => auth()->user()]
);

$result->successful;  // Collection of created invitations
$result->failed;      // Collection of failures with reasons

use OffloadProject\InviteOnly\Events\InvitationAccepted;

Event::listen(InvitationAccepted::class, function ($event) {
    $team = $event->invitation->invitable;
    $user = $event->user;
    $role = $event->invitation->role;

    $team->users()->attach($user->id, ['role' => $role]);
});

// routes/console.php
Schedule::command('invite-only:send-reminders --mark-expired')->daily();
bash
php artisan boost:add-skill offload-project/laravel-invite-only