Roles with Invitations for Staff Members

Some applications require users to register for a specific role. This will determine their functionality and what they see inside. For example, if it's a Job Listing Board, HR and Job seekers should see different things.

FilamentExamples ThumbBase (45)

Get the Source Code:

How it works

We start with a roles list in the PHP enum class, as these will be used in Registration:

app/Enum/Role.php:

enum Role: string
{
case JOB_SEEKERS = 'Job Seekers';
case MENTORS = 'Mentors';
case RECRUITERS = 'Recruiters';
case EMPLOYERS = 'Employers';
case FUSE_ADMIN = 'Fuse Admin';
}

Then we create a custom registration page to add a radio select input. From the roles list, we reject the role Fuse Admin.

This Roles radio select is visible only when cookie is_invited isn't set, as users are invited to a specific Role already.

In the mutateFormDataBeforeRegister() method, we handle the invitation when a user registers with the system. Here, we assign the user the Employers role and set the employer_id, which acts as a staff member for the employer.

app/Filament/Pages/Auth/Register.php:

use App\Models\Role;
use Filament\Forms\Form;
use App\Models\Invitation;
use Filament\Forms\Components\Radio;
use Illuminate\Support\Facades\Session;
use Filament\Forms\Components\Component;
use Filament\Pages\Auth\Register as BaseRegister;
 
class Register extends BaseRegister
{
protected function getForms(): array
{
return [
'form' => $this->form(
$this->makeForm()
->schema([
$this->getNameFormComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
$this->getRoleFormComponent(),
])
->statePath('data'),
),
];
}
// ...
}
The FULL tutorial is available after the purchase: in the Readme file of the official repository you would get invited to.
Get the Source Code: All 66 Premium Examples for $99