Filament Shield
Models
(more coming soon
😎
)
The easiest and most intuitive way to add access management to your Filament Resource One Plugin to rule them all, One Plugin to find them, One Plugin to bring them all, and in the light bind them, In the Land of Filament where building them is really fun!
Support Filament
Installation (New Apps)
- Install the package via composer:
composer require bezhansalleh/filament-shield
- Publish the config file with:
php artisan vendor:publish --tag="filament-shield-config"
- Change
super_admin_role_name
if you want. (You can skip this step if you use the default) Everypermission
generated will be automatically assigned to this role. Then you would be able to make auser
super admin by assigning this role to them.
'default_roles' => [
'super_admin_role_name' => 'super_admin',
'filament_user' => [
'role_name' => 'filament_user',
'enabled' => true
],
],
- Add the
Spatie\Permission\Traits\HasRoles
trait to your User model(s):
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasRoles;
// ...
}
- Now run the following command to setup everything:
php artisan shield:install
Follow the prompts and enjoy!
Installation (Existing Apps)
spatie/laravel-permission
already installed
Apps with - Follow the above steps from (1) thorugh (4) run the following command to setup everything:
php artisan shield:install --fresh
Beaware, that even though there are checks in place but if confirmed; existing policies might get overwritten.
RolePolicy
To ensure RoleResource
access via RolePolicy
you would need to add the following to your AuthServiceProvider
:
//AuthServiceProvider.php
...
protected $policies = [
'Spatie\Permission\Models\Role' => 'App\Policies\RolePolicy',
];
...
Optionally, you can publish the translations using
php artisan vendor:publish --tag="filament-shield-translations"
Available Filament Shield Commands
shield:create # Create Permissions and/or Policy for the given Filament Resource Model
shield:generate # (Re)Discovers Filament resources and (re)generates Permissions and Policies.
shield:install # One Command to Rule them All 🔥
shield:publish # Publish filament shield's Resource.
Chores
-
shield:install
command flow improved⚒️ - Improve documentation
📝 - A command to reverse everything
🤯 - handle
except
oronly
options for Permission and Policy generation👀 - improve automation or add new features...
⏭
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.