This plugin is built on top of Spatie's Permission 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 theapp/permission.php
file is set totrue
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
You can install the package via composer:
composer require althinect/filament-spatie-roles-permissions
Since the package depends on Spatie's Permission package. You have to publish the migrations by running:
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
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 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.
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
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
Policies will be generated with the respective permission. This won't replace any existing policies
php artisan permissions:sync -P|--policies
This will override existing policy classes
php artisan permissions:sync -O|--oep
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
- 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 theAuthServiceProvider
add the following
Gate::before(function (User $user, string $ability) {
return $user->isSuperAdmin() ? true: null;
});
In the filament-spatie-roles-permissions.php config file, you can customize the permission generation
If you discover any security related issues, please create an issue.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.