Configuration
NetPress Permissions stores a single piece of global configuration that drives the model table names, column names, and database connection. The shape is inspired by Laravel Spatie's config/permission.php and can be overridden per application.
The Default Shape
export default {
morphName: 'model',
driver: null,
connection: null,
pivotConnection: null,
tables: {
roles: 'roles',
permissions: 'permissions',
modelHasRoles: 'model_has_roles',
modelHasPermissions: 'model_has_permissions',
roleHasPermissions: 'role_has_permissions',
},
columns: {
id: 'id',
name: 'name',
description: 'description',
group: 'group',
modelPivot: 'modelId',
rolePivot: 'roleId',
permissionPivot: 'permissionId',
},
};
The vendor:publish command writes this structure to config/permissions.js. At boot the service provider calls configurePermissions(overrides) so the final resolved config reflects your application.
Fields Explained
morphName— drives the polymorphic column prefix.'model'means the pivot tables usemodelTypeandmodelIdcolumns. Set to'subject'if you prefersubjectType/subjectId.driver—'sql'or'mongo'. Published automatically by the publisher based on the connection you pick.connection— the Knex/Mongo connection name that holds the permissions tables.pivotConnection— the connection used for the pivot relation queries. Usually matchesconnection.tables.*— override any of the five table names (for example:acl_roles,acl_permissions).columns.*— override pivot and attribute column names if you are integrating with an existing schema.
Changing Config At Runtime
import { configurePermissions } from '@admicaa/netpress-permissions';
configurePermissions({
tables: { roles: 'acl_roles' },
columns: { rolePivot: 'role_id' },
});
configurePermissions merges your overrides on top of the defaults and then becomes the source of truth for every subsequent model and trait call. The models read from config lazily via static get table() so the change applies to queries you run right after.
Where The Provider Hooks In
NetpressPermissionsServiceProvider.register():
- Reads
config('permissions')from your application's config repository. - Merges those overrides into the package defaults.
- Calls
configurePermissions(...). - Binds the resolved shape into the container as
permissions.config.
If you subclass the provider (the publisher writes app/Providers/PermissionsServiceProvider.js for you), you can add custom bindings or load additional configuration before calling super.register().
Resetting For Tests
resetPermissionsConfig() restores the defaults and is useful in test teardown hooks to guarantee isolation:
import { resetPermissionsConfig } from '@admicaa/netpress-permissions';
afterEach(() => {
resetPermissionsConfig();
});