Filament: Roles with Spatie Permission Package

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


Get the Source Code:

How it works

The registration form is enabled in AdminPanelProvider.


class AdminPanelProvider extends PanelProvider
public function panel(Panel $panel): Panel
return $panel
->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.


class User extends Authenticatable implements FilamentUser
// ...
protected static function booted(): void
static::created(function (User $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.
Get the Source Code: All 50 Premium Examples for $99 Only Project Examples for $59