Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

Laravel Invite Only Adds a Full User Invitation System with Tokens, Events, and Reminders

Published on by

Laravel Invite Only Adds a Full User Invitation System with Tokens, Events, and Reminders image

The Laravel Invite Only package manages user invitations in Laravel applications. Created by Shavonn Brown, this package handles token-based invitations with polymorphic relationships, automatic reminders, and event-driven notifications.

Use Cases

The package works for applications that need invitation management with status tracking and follow-ups. Common scenarios include team collaboration tools, SaaS applications with organization memberships, project collaboration platforms, event management systems with RSVP tracking, and educational platforms that invite students to courses. The polymorphic design means one invitation system can handle teams, projects, organizations, or any other model in your application.

Main Features

Laravel Invite Only includes several features for managing invitations:

  • Polymorphic invitations that work with any model in your application
  • Bulk invitation support with partial failure handling
  • Secure token-based links for invitation acceptance
  • Status tracking across pending, accepted, declined, expired, and cancelled states
  • Automatic reminder emails via scheduled commands
  • Event system for all invitation lifecycle changes
  • Structured exceptions with error codes for debugging

Getting Started

Installation requires PHP 8.2+ and Laravel 11.0 or 12.0. Install the package via Composer:

composer require offload-project/laravel-invite-only

Publish the configuration and migrations:

php artisan vendor:publish --tag="invite-only-config"
php artisan vendor:publish --tag="invite-only-migrations"
php artisan migrate

Then, add the required HasInvitations and CanBeInvited traits to your models:

use OffloadProject\InviteOnly\Traits\HasInvitations;
 
class Event extends Model
{
use HasInvitations;
}
use OffloadProject\InviteOnly\Traits\CanBeInvited;
 
class User extends Authenticatable
{
use CanBeInvited;
}

Sending Invitations

The package supports both single and bulk invitations. For a single invitation:

$event->invite('user@example.com', [
'role' => 'vip',
'invited_by' => auth()->user(),
]);

For bulk invitations with partial failure handling:

$result = $event->inviteMany(
['eric@example.com', 'paul@example.com', 'harris@example.com'],
['role' => 'vip', 'invited_by' => auth()->user()]
);
 
// Access successful invitations
$result->successful;
 
// Check failed invitations with reasons
$result->failed;

Handling Invitation Acceptance

The package fires events at each stage of the invitation lifecycle. Listen for the InvitationAccepted event to perform actions when users accept invitations:

use OffloadProject\InviteOnly\Events\InvitationAccepted;
 
Event::listen(InvitationAccepted::class, function ($event) {
$conferenceEvent = $event->invitation->invitable;
$user = $event->user;
$role = $event->invitation->role;
 
$conferenceEvent->attendees()->attach($user->id, ['role' => $role]);
});

Other invitation events include InvitationCreated, InvitationDeclined, InvitationCancelled, and InvitationExpired.

Automatic Reminders

Configure automatic reminders to send follow-up emails for pending invitations. The configuration allows you to specify which days reminders should be sent:

'reminders' => [
'after_days' => [3, 5], // Send reminders on day 3 and day 5
'max_reminders' => 2,
],

Schedule the reminder command in your routes/console.php file:

use Illuminate\Support\Facades\Schedule;
 
Schedule::command('invite-only:send-reminders --mark-expired')->daily();

The system tracks the reminder count to avoid sending duplicate notifications, even if the scheduler misses a day. Invitations can be configured to expire after a specified number of days (7 days by default), and the same command automatically marks expired invitations when running with the --mark-expired flag.

Polymorphic Relationships

One of the package's strengths is its polymorphic design. You can attach invitations to any model in your application:

// Conference event invitations
$conferenceEvent->invite('speaker@example.com');
 
// Workshop invitations
$workshop->invite('attendee@example.com');
 
// Meetup invitations
$meetup->invite('participant@example.com');

This works for applications with multiple types of entities that require invitation systems.

Custom Metadata

Store additional information with invitations using the metadata column:

$event->invite('speaker@example.com', [
'metadata' => [
'session_topic' => 'Laravel AI SDK',
'time_slot' => '2:00 PM',
'dietary_restrictions' => 'vegetarian',
],
]);
 
// Retrieve metadata later
$invitation->metadata['session_topic']; // 'Laravel Performance'

This allows you to attach custom data without modifying the database schema.

Error Handling

The package provides structured exceptions with machine-readable error codes:

try {
InviteOnly::accept($token);
} catch (InvitationException $e) {
// Human-readable message
$e->getMessage(); // "This invitation has expired."
 
// Suggested resolution
$e->resolution; // "Create a new invitation..."
 
// Machine-readable code
$e->errorCode; // "INVITATION_EXPIRED"
}

This makes it easier to build API endpoints and provide meaningful feedback to users.

To learn more about Laravel Invite Only and view the source code, visit the GitHub repository.

Yannick Lyn Fatt photo

Staff Writer at Laravel News and Full stack web developer.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Curotec

Curotec helps software teams hire the best Laravel developers in Latin America. Click for rates and to learn more about how it works.

Visit Curotec
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Cut PHP Code Review Time & Bugs into Half with CodeRabbit logo

Cut PHP Code Review Time & Bugs into Half with CodeRabbit

CodeRabbit is an AI-powered code review tool that specializes in PHP and Laravel, running PHPStan and offering automated PR analysis, security checks, and custom review features while remaining free for open-source projects.

Cut PHP Code Review Time & Bugs into Half with CodeRabbit
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit

The latest

View all →
Laravel Invite Only Adds a Full User Invitation System with Tokens, Events, and Reminders image

Laravel Invite Only Adds a Full User Invitation System with Tokens, Events, and Reminders

Read article
Docker Support in Laravel VS Code Extension v1.4.2 image

Docker Support in Laravel VS Code Extension v1.4.2

Read article
Laravel Deadlock: Manage Technical Debt with Expiring Code Markers image

Laravel Deadlock: Manage Technical Debt with Expiring Code Markers

Read article
Filament v5 Released With Livewire v4 Support and a New Blueprint Tool image

Filament v5 Released With Livewire v4 Support and a New Blueprint Tool

Read article
Async Request Cancellation Updates in Inertia v2.3.10 image

Async Request Cancellation Updates in Inertia v2.3.10

Read article
FluentVox: AI Text-to-Speech for Laravel with Voice Cloning and GPU Acceleration image

FluentVox: AI Text-to-Speech for Laravel with Voice Cloning and GPU Acceleration

Read article