PHPackages                             liberusoftware/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. liberusoftware/filament-spatie-roles-permissions

ActiveLibrary

liberusoftware/filament-spatie-roles-permissions
================================================

v2.3.1(2y ago)047[1 PRs](https://github.com/liberusoftware/filament-spatie-roles-permissions/pulls)MITPHPPHP ^8.1|^8.2

Since Feb 27Pushed 2y agoCompare

[ Source](https://github.com/liberusoftware/filament-spatie-roles-permissions)[ Packagist](https://packagist.org/packages/liberusoftware/filament-spatie-roles-permissions)[ Docs](https://github.com/althinect/filament-spatie-roles-permissions)[ RSS](/packages/liberusoftware-filament-spatie-roles-permissions/feed)WikiDiscussions 2.x Synced today

READMEChangelog (2)Dependencies (5)Versions (4)Used By (0)

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/actions/workflows/main.yml/badge.svg)

This plugin is built on top of [Spatie's Permission](https://spatie.be/docs/laravel-permission/v6/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/v5/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"
```

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
```

#### 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.

### 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)

- [Tharinda Rodrigo](https://github.com/tharindarodrigo/)
- [Udam Liyanage](https://github.com/UdamLiyanage/)
- [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

27

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.1% of commits — single point of failure

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 ~0 days

Total

3

Last Release

753d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a970cf00380cf02d4ff7d625d64e8975d60e5360289e7a6ff2a0c730f6aef66?d=identicon)[curtisdelicata](/maintainers/curtisdelicata)

---

Top Contributors

[![tharindarodrigo](https://avatars.githubusercontent.com/u/9903811?v=4)](https://github.com/tharindarodrigo "tharindarodrigo (79 commits)")[![tonypartridge](https://avatars.githubusercontent.com/u/1400982?v=4)](https://github.com/tonypartridge "tonypartridge (13 commits)")[![fsamapoor](https://avatars.githubusercontent.com/u/4992968?v=4)](https://github.com/fsamapoor "fsamapoor (3 commits)")[![celaraze](https://avatars.githubusercontent.com/u/31471452?v=4)](https://github.com/celaraze "celaraze (3 commits)")[![UdamLiyanage](https://avatars.githubusercontent.com/u/20433694?v=4)](https://github.com/UdamLiyanage "UdamLiyanage (3 commits)")[![curtisdelicata](https://avatars.githubusercontent.com/u/179251?v=4)](https://github.com/curtisdelicata "curtisdelicata (3 commits)")[![HomaEEE](https://avatars.githubusercontent.com/u/1429343?v=4)](https://github.com/HomaEEE "HomaEEE (3 commits)")[![bb140856](https://avatars.githubusercontent.com/u/71066181?v=4)](https://github.com/bb140856 "bb140856 (2 commits)")[![mohamedsabil83](https://avatars.githubusercontent.com/u/10126040?v=4)](https://github.com/mohamedsabil83 "mohamedsabil83 (2 commits)")[![ousid](https://avatars.githubusercontent.com/u/21012933?v=4)](https://github.com/ousid "ousid (2 commits)")[![dinwwwh](https://avatars.githubusercontent.com/u/64189902?v=4)](https://github.com/dinwwwh "dinwwwh (2 commits)")[![encoderuz](https://avatars.githubusercontent.com/u/43345536?v=4)](https://github.com/encoderuz "encoderuz (2 commits)")[![LuizCristino](https://avatars.githubusercontent.com/u/33782549?v=4)](https://github.com/LuizCristino "LuizCristino (2 commits)")[![pnm1231](https://avatars.githubusercontent.com/u/1593448?v=4)](https://github.com/pnm1231 "pnm1231 (1 commits)")[![SychO9](https://avatars.githubusercontent.com/u/20267363?v=4)](https://github.com/SychO9 "SychO9 (1 commits)")[![thomas672](https://avatars.githubusercontent.com/u/16239079?v=4)](https://github.com/thomas672 "thomas672 (1 commits)")[![anoshiri](https://avatars.githubusercontent.com/u/28390917?v=4)](https://github.com/anoshiri "anoshiri (1 commits)")[![webpatser](https://avatars.githubusercontent.com/u/25720?v=4)](https://github.com/webpatser "webpatser (1 commits)")[![barisaksu](https://avatars.githubusercontent.com/u/4641951?v=4)](https://github.com/barisaksu "barisaksu (1 commits)")[![CodeTechNL](https://avatars.githubusercontent.com/u/65519422?v=4)](https://github.com/CodeTechNL "CodeTechNL (1 commits)")

---

Tags

althinectfilament-spatie-roles-permissions

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[althinect/filament-spatie-roles-permissions

340893.6k8](/packages/althinect-filament-spatie-roles-permissions)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.7k2.6M73](/packages/bezhansalleh-filament-shield)[rupadana/filament-api-service

A simple api service for supporting filamentphp

20399.6k7](/packages/rupadana-filament-api-service)[chiiya/filament-access-control

Admin user, role and permission management for Laravel Filament

21845.5k](/packages/chiiya-filament-access-control)[phpsa/filament-authentication

User &amp; Role (via Spatie Roles/Permissions) Manager Resource For Filament Admin

12561.4k](/packages/phpsa-filament-authentication)[solution-forest/filament-access-management

filament-access-management

9457.0k](/packages/solution-forest-filament-access-management)

PHPackages © 2026

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