config/permission.php file contains all configuration options for Laravel Permission. This guide documents every available option with examples and use cases.
Publishing the Config File
Publish the configuration file using:Configuration Structure
Models Configuration
Define which Eloquent models to use for permissions and roles.The Eloquent model used for permissions. Must implement
Spatie\Permission\Contracts\Permission contract.Example:The Eloquent model used for roles. Must implement
Spatie\Permission\Contracts\Role contract.Example:Table Names Configuration
Customize the database table names used by the package.Table name for storing roles.Example:
Table name for storing permissions.Example:
Pivot table for model-to-permission relationships.Example:
Pivot table for model-to-role relationships.Example:
Pivot table for role-to-permission relationships.Example:
Column Names Configuration
Customize column names used in pivot tables and relationships.Custom name for the role foreign key in pivot tables. Defaults to
role_id when null.Example:Custom name for the permission foreign key in pivot tables. Defaults to
permission_id when null.Example:The column name for the morph key in polymorphic relationships. Useful when using UUIDs.Example:
The foreign key column name used for teams feature.Example:
Permission Check Registration
When enabled, registers the permission check method on Laravel’s Gate. Set to
false if you want to implement custom permission checking logic.Example:Octane Support
When enabled, registers a Example:
Laravel\Octane\Events\OperationTerminated event listener that refreshes permissions on every TickTerminated, TaskTerminated, and RequestTerminated event.This is typically only needed for specific Octane/Vapor configurations. Most applications should keep this disabled.
Events Configuration
Enable or disable permission and role assignment/unassignment events.Available Events:Then create event listeners:
Spatie\Permission\Events\RoleAttachedEventSpatie\Permission\Events\RoleDetachedEventSpatie\Permission\Events\PermissionAttachedEventSpatie\Permission\Events\PermissionDetachedEvent
Teams Feature
Enable multi-tenancy support using teams. When enabled, permissions and roles are scoped to teams.Example:
The class responsible for resolving the current team ID. Customize this to implement your own team resolution logic.Example:Your custom resolver must implement
Spatie\Permission\Contracts\PermissionsTeamResolver:Passport Integration
Enable Laravel Passport Client Credentials Grant support for checking permissions.Example:
Exception Messages
When enabled, permission names are included in authorization exception messages.Example:With this enabled, exceptions will show:
When enabled, role names are included in authorization exception messages.Example:With this enabled, exceptions will show:
Wildcard Permissions
Enable wildcard permission matching. Allows using patterns like Usage:
articles.* to match articles.create, articles.edit, etc.Example:The class used for interpreting wildcard permissions. Override to customize wildcard delimiters and matching logic.Example:
This option is commented out by default. Uncomment and set a custom class if needed.
Cache Configuration
How long permissions are cached. The cache is automatically flushed when permissions or roles are updated.Example:
The cache key used to store all permissions.Example:
The cache driver to use for permission caching. Must match a store configured in
config/cache.php.Example:Complete Configuration Example
Here’s a complete example with commonly customized options:config/permission.php
Configuration Tips
Teams setup
If enabling teams, do it before running migrations or use
permission:setup-teams afterward.Cache configuration
Consider using Redis for the cache store in production environments for better performance.
Most applications work perfectly with the default configuration. Only customize options when you have specific requirements.