@luminix/laravel-permission-for-mui-cms
v1.1.0
Published
Integrates [spatie/laravel-permission](https://github.com/spatie/laravel-permission) with the Luminix MUI CMS admin panel. Adds a permissions selector to the Role form and a roles selector to any model with `has_roles` in its schema.
Readme
@luminix/laravel-permission-for-mui-cms
Integrates spatie/laravel-permission with the Luminix MUI CMS admin panel. Adds a permissions selector to the Role form and a roles selector to any model with has_roles in its schema.
Setup
Register the provider in your LuminixCms entry point:
import { LuminixCms } from '@luminix/mui-cms';
import { PermissionServiceProvider } from '@luminix/laravel-permission-for-mui-cms';
<LuminixCms providers={[PermissionServiceProvider, AppServiceProvider]} />Customization
Customizations follow the Luminix reducer pattern — register them in your app's ServiceProvider.boot(), after PermissionServiceProvider.
Hiding permissions from the Role form
Use the Permissions facade to hide permissions from the selector shown when editing roles. hidePermissions() accepts permission names, RegExp patterns or predicates:
import { ServiceProvider } from '@luminix/support';
import { Permissions } from '@luminix/laravel-permission-for-mui-cms';
export default class AppServiceProvider extends ServiceProvider {
boot() {
Permissions.hidePermissions(
'manage-system', // exact name
/^internal-/, // pattern
(p) => p.guard_name === 'api', // predicate
);
}
}For full control, register a visiblePermissions reducer directly. It receives the permission collection and the current form data (the role being edited):
Permissions.reducer('visiblePermissions', (permissions, role) => {
if (role.name === 'editor') {
return permissions.filter((p) => !(p.name as string).startsWith('delete-'));
}
return permissions;
});Hidden permissions are only removed from the UI — permissions already assigned to a role remain assigned and are preserved on save.
