PHP code example of jhonoryza / filament-simple-role-permission
1. Go to this page and download the library: Download jhonoryza/filament-simple-role-permission library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jhonoryza / filament-simple-role-permission example snippets
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',
]
}
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 => '',
};
}
bash
php artisan filament-simple-role-permission:install
bash
php artisan migrate
bash
php artisan db:seed --class=PermissionSeeder
php artisan db:seed --class=RoleSeeder
php artisan db:seed --class=UserSeeder
bash
php artisan policy:generate
bash
php artisan vendor:publish --tag="simple-role-permission-stubs"