Download the PHP package oltrematica/laravel-role-lite without Composer
On this page you can find all versions of the php package oltrematica/laravel-role-lite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oltrematica/laravel-role-lite
More information about oltrematica/laravel-role-lite
Files in oltrematica/laravel-role-lite
Package laravel-role-lite
Short Description a lightweight Laravel package that provides simple role management functionality.
License MIT
Informations about the package laravel-role-lite
Laravel Role Lite
A lightweight role and permission management package for Laravel applications.
Laravel Role Lite provides a simple, intuitive API for managing roles and permissions. Assign roles to users, attach permissions to roles, and check access throughout your application with minimal configuration. The permissions system is opt-in: if you only need roles, skip the permission migrations and the feature stays out of your way.
Prerequisites
- Laravel v10, v11, v12, or v13
- PHP 8.3 or higher
Installation
Publish and run the role migrations:
Optional — permissions system. If you also want database-driven permissions, publish and run the permission migrations:
Configuration
The default configuration works for most applications. To customise it, publish the config file:
The published file lives at config/oltrematica-role-lite.php.
Table Names
Model Names
Permissions Settings
Roles
Setup
Add the HasRoles trait to your User model (or any Eloquent model):
Using a BackedEnum for role names is recommended — it keeps role identifiers in one place and prevents typos:
Assigning Roles
Checking Roles
Permissions
Permissions are stored in the database and assigned to roles — not directly to users. A user gains a permission through any of their roles.
Setup
Add HasPermissions to your User model. It requires HasRoles to also be present:
Creating Permissions
Granting and Revoking Permissions
Permissions are granted/revoked at the role level:
You can also grant/revoke via the user, which targets the user's first role by default or a specific role:
Checking Permissions
Using Permissions in Laravel Policies
The ChecksPermissions trait simplifies writing database-driven policies. It automatically derives the model name from the policy class name (CustomerPolicy → customer, ServiceVisitPolicy → service_visit):
If the model class cannot be inferred from the policy name, pass it explicitly:
You can also resolve the permission name without performing a check:
PermissionService and Cache Management
PermissionService is a singleton that loads all role-permission mappings into a two-tier cache (in-memory + distributed). This means permission checks within the same request never hit the database more than once.
The cache is cleared automatically whenever you call grantPermission, revokePermission, or syncPermissions on a role.
If you need to clear it manually — for example after bulk database operations:
Configure caching behaviour in config/oltrematica-role-lite.php:
Events
The package fires events for role and permission changes that you can listen to in your application.
Role Events
| Event | Fired when |
|---|---|
Oltrematica\RoleLite\Events\UserRoleCreated |
A role is assigned to a user |
Oltrematica\RoleLite\Events\UserRoleDeleted |
A role is removed from a user |
Oltrematica\RoleLite\Events\UserRoleUpdated |
A role assignment is updated |
Permission Events
| Event | Fired when |
|---|---|
Oltrematica\RoleLite\Events\PermissionGranted |
A permission is granted to a role |
Oltrematica\RoleLite\Events\PermissionRevoked |
A permission is revoked from a role |
Both permission events receive a PermissionRole pivot model with role_id and permission_id properties.
Code Quality
Rector
PhpStan
Pint
Automated Tests
Contributing
Feel free to contribute by submitting issues or pull requests. We welcome any improvements or bug fixes.