PHPackages                             althinect/filament-spatie-roles-permissions - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. althinect/filament-spatie-roles-permissions

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

althinect/filament-spatie-roles-permissions
===========================================

v3.3.1(2mo ago)340954.7k—7.3%119[12 issues](https://github.com/Althinect/filament-spatie-roles-permissions/issues)[1 PRs](https://github.com/Althinect/filament-spatie-roles-permissions/pulls)8MITPHPPHP ^8.2CI failing

Since Apr 15Pushed 2mo ago8 watchersCompare

[ Source](https://github.com/Althinect/filament-spatie-roles-permissions)[ Packagist](https://packagist.org/packages/althinect/filament-spatie-roles-permissions)[ Docs](https://github.com/althinect/filament-spatie-roles-permissions)[ RSS](/packages/althinect-filament-spatie-roles-permissions/feed)WikiDiscussions 3.x Synced 1mo ago

READMEChangelog (10)Dependencies (26)Versions (105)Used By (8)

Description
===========

[](#description)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1448c125a99ffd343d08208ff644bae05c64f250cb91ebdc9e38f01a5ef55080/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c7468696e6563742f66696c616d656e742d7370617469652d726f6c65732d7065726d697373696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/althinect/filament-spatie-roles-permissions)[![Total Downloads](https://camo.githubusercontent.com/88266de835a3ff467c31d4f78be70c54f7b72c881ea7f357410f8738286bc4f9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c7468696e6563742f66696c616d656e742d7370617469652d726f6c65732d7065726d697373696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/althinect/filament-spatie-roles-permissions)[![GitHub Actions](https://github.com/althinect/filament-spatie-roles-permissions/actions/workflows/main.yml/badge.svg)](https://github.com/Althinect/filament-spatie-roles-permissions)

This plugin is built on top of [Spatie's Permission](https://spatie.be/docs/laravel-permission/v7/introduction) package.

Provides Resources for Roles and Permissions

Permission and Policy generations

- Check the `config/filament-spatie-roles-permissions-config.php`

Supports permissions for teams

- Make sure the `teams` attribute in the `config/permission.php` file is set to `true`

Updating
--------

[](#updating)

After performing a `composer update`, run

```
php artisan vendor:publish --tag="filament-spatie-roles-permissions-config" --force
```

***Note that your existing settings will be overriden***

#### If you like our work Don't forget to STAR the project

[](#if-you-like-our-work-dont-forget-to-star-the-project)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require althinect/filament-spatie-roles-permissions
```

Since the package depends on [Spatie's Permission](https://spatie.be/docs/laravel-permission/v7/introduction) package. You have to publish the migrations by running:

```
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
```

Add the plugin to the `AdminPanelProvider`

```
use Althinect\FilamentSpatieRolesPermissions\FilamentSpatieRolesPermissionsPlugin;

$panel
    ...
    ->plugin(FilamentSpatieRolesPermissionsPlugin::make())
```

Now you should add any other configurations needed for the Spatie-Permission package.

**Note:** This will override your existing config file. You can publish the config file of the package with:

```
php artisan vendor:publish --tag="filament-spatie-roles-permissions-config" --force
```

You can publish translations with:

```
php artisan vendor:publish --tag="filament-spatie-roles-permissions-translations"
```

Don't forget to add the `HasRoles` trait to your User model.

```
 // The User model requires this trait
 use HasRoles;
```

Usage
-----

[](#usage)

### Form

[](#form)

You can add the following to your *form* method in your UserResource

```
return $form->schema([
    Select::make('roles')->multiple()->relationship('roles', 'name')
])
```

In addition to the field added to the **UserResource**. There will be 2 Resources published under *Roles and Permissions*. You can use these resources manage roles and permissions.

### Generate Permissions

[](#generate-permissions)

You can generate Permissions by running

```
php artisan permissions:sync
```

This will not delete any existing permissions. However, if you want to delete all existing permissions, run

```
php artisan permissions:sync -C|--clean
```

There may be an occassion where you wish to hard reset and truncate your existing permissions. To delete all permissions and reset the primary key, run

```
php artisan permissions:sync -H|--hard
```

#### Example:

[](#example)

If you have a **Post** model, it will generate the following permissions

```
view-any Post
view Post
create Post
update Post
delete Post
restore Post
force-delete Post
replicate Post
reorder Post

```

### Generating Policies

[](#generating-policies)

To generate policies use the command below. This won't replace any existing policies

```
php artisan permissions:sync -P|--policies
```

### Overriding existing Policies

[](#overriding-existing-policies)

This will override existing policy classes

```
php artisan permissions:sync -O|--oep
```

### Role and Permission Policies

[](#role-and-permission-policies)

Create a RolePolicy and PermissionPolicy if you wish to control the visibility of the resources on the navigation menu. Make sure to add them to the AuthServiceProvider.

> **ℹ️ Info:** *Laravel 11 removed `AuthServiceProvider`, so, in this case, we need to use `AppServiceProvider` instead.*

```
use App\Policies\RolePolicy;
use App\Policies\PermissionPolicy;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;

Gate::policy(Role::class, RolePolicy::class);
Gate::policy(Permission::class, PermissionPolicy::class);
```

### Ignoring prompts

[](#ignoring-prompts)

You can ignore any prompts by add the flag `-Y` or `--yes-to-all`

***Recommended only for new projects as it will replace Policy files***

```
php artisan permissions:sync -COPY
```

### Adding a Super Admin

[](#adding-a-super-admin)

- Create a Role with the name `Super Admin` and assign the role to a User
- Add the following trait to the User Model

```
use Althinect\FilamentSpatieRolesPermissions\Concerns\HasSuperAdmin;

class User extends Authenticatable{

...
use HasSuperAdmin;
```

- In the `boot` method of the `AuthServiceProvider` add the following

```
Gate::before(function (User $user, string $ability) {
    return $user->isSuperAdmin() ? true: null;
});
```

### Guard Names

[](#guard-names)

When you use any guard other than `web` you have to add the guard name to the `config/auth.php` file. Example: If you use `api` guard, you should add the following to the `guards` array

```
'guards' => [
    ...

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
        'hash' => false,
    ],
],
```

### Tenancy

[](#tenancy)

- Make sure to set the following on the `config/permission.php`

```
'teams' => true
```

- Make sure the `team_model` on the `config/permission` is correctly set.
- Create a Role model which extends `Spatie\Permission\Models\Role`
- Replace the model in the `config/permission.php` with the newly created models
- Add the `team` relationship in both models

```
...
public function team(): BelongsTo
{
    return $this->belongsTo(Team::class);
}
```

- Add the following to the `AdminPanelProvider` to support tenancy

```
use Althinect\FilamentSpatieRolesPermissions\Middleware\SyncSpatiePermissionsWithFilamentTenants;

$panel
    ...
    ->tenantMiddleware([
        SyncSpatiePermissionsWithFilamentTenants::class,
    ], isPersistent: true)
```

- Use the following within you UserResource

```
Forms\Components\Select::make('roles')
            ->relationship(name: 'roles', titleAttribute: 'name')
            ->saveRelationshipsUsing(function (Model $record, $state) {
                 $record->roles()->syncWithPivotValues($state, [config('permission.column_names.team_foreign_key') => getPermissionsTeamId()]);
            })
           ->multiple()
           ->preload()
           ->searchable(),

```

Follow the instructions on [Filament Multi-tenancy](https://filamentphp.com/docs/3.x/panels/tenancy)

### Configurations

[](#configurations)

In the **filament-spatie-roles-permissions.php** config file, you can customize the permission generation

Security
--------

[](#security)

If you discover any security related issues, please create an issue.

Credits
-------

[](#credits)

- [Althinect](https://github.com/Althinect/)
- [Contributors](https://github.com/Althinect/filament-spatie-roles-permissions/graphs/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

66

—

FairBetter than 99% of packages

Maintenance86

Actively maintained with recent releases

Popularity61

Solid adoption and visibility

Community23

Small or concentrated contributor base

Maturity77

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Recently: every ~6 days

Total

101

Last Release

65d ago

Major Versions

v1.3.7 → v2.0.52023-09-06

v1.3.9 → v2.0.142023-10-07

1.x-dev → v2.2.02023-10-27

v2.3.2 → v3.02026-01-23

v2.3.3 → v3.3.12026-03-14

PHP version history (4 changes)v1.0.0PHP ^7.4|^8.0|^8.1

v1.0.4PHP ^7.4|^8.0|^8.1|^8.2

v2.0PHP ^8.1|^8.2

v3.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/483e118a57e1fb365b9891ad1ad8ba0e526897091e663eb3db830a0ec0890fcb?d=identicon)[udamliyanage](/maintainers/udamliyanage)

![](https://www.gravatar.com/avatar/c7cfdca537dc8e3e84fcbd9b9fbebec510c7659693983e9804159c2e2321ef46?d=identicon)[tharindarodrigo](/maintainers/tharindarodrigo)

---

Tags

althinectfilament-spatie-roles-permissions

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/althinect-filament-spatie-roles-permissions/health.svg)

```
[![Health](https://phpackages.com/badges/althinect-filament-spatie-roles-permissions/health.svg)](https://phpackages.com/packages/althinect-filament-spatie-roles-permissions)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[andrewdwallo/filament-companies

A comprehensive Laravel authentication and authorization system designed for Filament, focusing on multi-tenant company management.

34450.0k2](/packages/andrewdwallo-filament-companies)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
