Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jhonoryza/filament-simple-role-permission
Laravel Filament Simple Role and Permission Plugin Scaffolding
https://github.com/jhonoryza/filament-simple-role-permission
filamentphp laravel livewire permission role
Last synced: 2 months ago
JSON representation
Laravel Filament Simple Role and Permission Plugin Scaffolding
- Host: GitHub
- URL: https://github.com/jhonoryza/filament-simple-role-permission
- Owner: jhonoryza
- License: mit
- Created: 2024-07-29T08:36:36.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-27T06:50:35.000Z (4 months ago)
- Last Synced: 2024-10-01T09:21:59.524Z (3 months ago)
- Topics: filamentphp, laravel, livewire, permission, role
- Language: PHP
- Homepage:
- Size: 1.15 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Simple Role Permission Filament
This package is a filament scaffolding for simple role and permission, provides filament resources, models, migration, seeder and policy generator
## Screenshot
## ERD
## Requirements
- PHP >= 8.2
- Laravel >= 10.0
- Filament >= 3.0## Installation
You can install the package via composer
```bash
composer require --dev jhonoryza/filament-simple-role-permission
```Then you need to run this command to publish the scaffolding
```bash
php artisan filament-simple-role-permission:install
```Then you can migrate your database
```bash
php artisan migrate
```Edit `app\Models\User.php` add `HasRole` trait and `predefined roles`
```php
use App\Models\Concern\HasRole;
class User extends Authenticatable
{
use HasRole;const SUPER = 'super-admin';
const ADMIN = 'admin';
public static function getPredefined(): array
{
return [
self::SUPER,
self::ADMIN,
];
}protected $fillable = [
// ... etc'role_id',
]
}
````const SUPER` is used in `UserSeeder` class
Then seed it with some default role and permission
```bash
php artisan db:seed --class=PermissionSeeder
php artisan db:seed --class=RoleSeeder
php artisan db:seed --class=UserSeeder
```Then generate all policy file in `app\Policies` directory base on `predefined` permissions from Permission model
```bash
php artisan policy:generate
```## Configuration
You can configure predefined permissions by adjust `function getPredefined()` and `function match()` in `Permission` model class like this
```php
public static function getPredefined(): array
{
return [
'users' => [
'view-any',
'view',
'create',
'update',
'delete',
'bulk-delete',
],
'roles' => [
'view-any',
'view',
'create',
'update',
'delete',
'bulk-delete',
],
'permissions' => [
'view-any',
'view',
'create',
'update',
'delete',
'bulk-delete',
],
];
}public static function match($permission): string
{
return match ($permission) {
'view-any' => 'viewAnyPermission',
'view' => 'viewPermission',
'create' => 'createPermission',
'update' => 'updatePermission',
'delete' => 'deletePermission',
'bulk-delete' => 'bulkDeletePermission',
default => '',
};
}
```## Publishing policy stubs
To customize Policy class template:
```bash
php artisan vendor:publish --tag="simple-role-permission-stubs"
```## Security
If you discover any security related issues, please create an issue.
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.