1. Go to this page and download the library: Download vimatech/laravel-invitation 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/ */
vimatech / laravel-invitation example snippets
// 1. Send an invitation
$invitation = Invitations::to('[email protected]')
->for($project)
->invitedBy(auth()->user())
->send();
// 2. Accept the invitation (via token from email)
Invitations::accept($token, auth()->user());
use Vimatech\Invitation\Facades\Invitations;
$invitation = Invitations::to('[email protected]')->send();
$invitation = Invitations::toUser($user)
->for($project)
->send();
// Or via the HasInvitations trait:
$project->inviteUser($user)->send();
use Illuminate\Database\Eloquent\Model;
use Vimatech\Invitation\Concerns\HasInvitations;
class Project extends Model
{
use HasInvitations;
}
// Then:
$project->invite('[email protected]')
->invitedBy($user)
->expiresInDays(10)
->withMeta(['role' => 'member'])
->send();
// List invitations
$project->invitations;
$project->pendingInvitations;
$invitation = Invitations::accept($token, $user);
// After user registration (verifies the invitation email matches the user's email):
$invitation = Invitations::acceptForNewUser($token, $newUser);
Invitations::to('[email protected]')
->expiresInDays(30)
->send();
// Or with a specific date:
Invitations::to('[email protected]')
->expiresAt(now()->addWeeks(2))
->send();
// Per invitation:
Invitations::to('[email protected]')
->for($user)
->neverExpires()
->send();
// Or globally via config:
// 'expires_after_days' => null,
use Vimatech\Invitation\Events\InvitationAccepted;
Event::listen(InvitationAccepted::class, function ($event) {
$event->invitation->subject->members()->attach($event->user);
});
use Vimatech\Invitation\Contracts\AcceptsInvitations;
use Vimatech\Invitation\Models\Invitation;
use Illuminate\Database\Eloquent\Model;
class MyAcceptanceHandler implements AcceptsInvitations
{
public function accept(Invitation $invitation, ?Model $user = null): void
{
// Your logic here
}
}