Roles with Spatie Permission Package

Filament 3
Also available in Filament 4/5 version

Demonstrates how to use spatie/laravel-permission package in Filament and auto-assign a role when the user registers for the application.

filament-examples-roles-and-permissions

Get the Source Code:

Only This Example

$9

One-time payment

Full source code for Roles with Spatie Permission Package
Downloadable ZIP file with the source code
Lifetime access to this example
GitHub Sign in with GitHub to buy

Sign in first, then complete your $9 checkout.

Best value — all 168 examples

FilamentExamples Membership

$99 /year
or
$199 lifetime
Access to code of all 168 examples
Future new examples and updates included
FilaCheck Pro package licence included
MCP server included
View membership plans

30-day money-back guarantee

How it works

The registration form is enabled in AdminPanelProvider.

app/Providers/Filament/AdminPanelProvider.php:

class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->registration() // here we enable registration feature
// ...
}
}

The spatie/laravel-permission package is used for the roles and permissions. Two roles are seeded: admin and user.

When a new user registers to the application, the user role is assigned using the closure Eloquent event created.

app/Models/User.php:

class User extends Authenticatable implements FilamentUser
{
// ...
 
protected static function booted(): void
{
static::created(function (User $user) {
$user->assignRole('user');
});
}
 
// ...
}

In the Admin Panel, we have two Filament resources: TaskResource and UserResource.

The UserResource menu item "Users" can only be seen by the user with an admin role.

For that...

The FULL tutorial is available after the purchase: in the Readme file of the official repository you would get invited to.