z3d0x / filament-simple-permissions
Simply define the permissions in the filament resource.
Requires
- php: ^8.0|^8.1|^8.2
- filament/filament: ^2.10
- illuminate/contracts: ^8.0|^9.0|^10.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2023-08-13 04:38:31 UTC
README
Warning
This package is no longer maintained
Simply define the permissions in the filament resource.
Easily define permissions for Filament Resources & Relation Managers
Installation
You can install the package via composer:
composer require z3d0x/filament-simple-permissions
This package does not require any additional configuration after installation
Usage
This package comes with two traits HasResourcePermissions
and HasRelationManagerPermissions
, which can be used in Filament's Resources and RelationManagers respectively.
To use simply use the trait in your Resource/RelationManger and define your permissions.
Resource Example
//UserResource.php use Z3d0X\FilamentSimplePermissions\Concerns\HasResourcePermissions; class UserResource extends Resource { use HasResourcePermissions; protected static array $permissions = [ 'viewAny' => 'access-users', 'view' => 'access-users', 'create' => 'create-users', 'update' => 'update-users', 'delete' => ['update-users', 'delete-stuff'], //use an array if multiple permissions are needed 'deleteAny' => false, //also supports boolean, to allow/disallow for all users ]; }
RelationManager Example
//PostsRelationManager.php use Z3d0X\FilamentSimplePermissions\Concerns\HasRelationManagerPermissions; class PostsRelationManager extends HasManyRelationManager { use HasRelationManagerPermissions; protected static array $permissions = [ 'create' => 'create-posts', 'update' => 'update-posts', 'delete' => ['update-posts', 'delete-stuff'], //use an array if multiple permissions are needed 'deleteAny' => false, //also supports boolean, to allow/disallow for all users //Supports relation manager specific actions. 'viewForRecord' => 'access-posts', 'associate' => 'update-posts', 'dissociate' => 'update-posts', 'dissociateAny' => false, ]; }
Advanced Usage
For advanced usage, it is possible to define a static getPermissions()
method, instead of $permissions
property
//PostsRelationManager.php use Z3d0X\FilamentSimplePermissions\Concerns\HasRelationManagerPermissions; use Illuminate\Database\Eloquent\Model; class PostsRelationManager extends HasManyRelationManager { use HasRelationManagerPermissions; protected static function getPermissions(): array { return [ 'viewForRecord' => fn (Model $ownerRecord) => $ownerRecord->user_id === auth()->id(), 'update' => function (Model $record) { return $record->user_id === auth()->id(); }, ]; } }
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.