Download the PHP package xetreon/role-permission without Composer
On this page you can find all versions of the php package xetreon/role-permission. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xetreon/role-permission
More information about xetreon/role-permission
Files in xetreon/role-permission
Package role-permission
Short Description An Api based Role Permission management system for PHP
License MIT
Informations about the package role-permission
Xetreon Role Permission for Laravel
A lightweight and flexible role and permission management package for Laravel. It allows you to manage roles, assign permissions, and automatically generate permissions from your controllers. Supports super admin bypass and custom authentication drivers.
☕ Support Me
If you find this package helpful, consider supporting my work:
Installation
Install via Composer:
Laravel 12 Integration
- Add the Service Provider
For Laravel 12 (add in bootstrap/providers.php):
For older Laravel versions (add in config/app.php):
-
Add the Service Provider
- Add the Service Provider
Configuration
The configuration file role-permission.php contains the following options:
Explanation of Key Options:
Usage
- Add Trait to User Model
Artisan Commands
- Generate All Permissions
Scans the configured controller directory and Generates permissions for all controller methods (index, create, update, destroy by default). This also Skips controllers listed in exclude.
- Seed Super Admin Role
Seeds the Super Admin role in your database and assign a user as Super Admin by providing their ID. Automatically bypasses all permission checks if is true.
Methods
– Assigns a role to a user.
– Removes all roles from a user.
– Returns all roles of the user.
– Returns the first assigned role.
Query scopes
– Filter users by role code.
– Filter users by role ID.
Check Permissions in Controllers
Add this to any controller to check user permissions:
Allowed Methods in controller
– Checks if the authenticated user has permission for the method.
Core Authentication Drivers
– Default driver using your Auth::getAuth() method.
– Uses Laravel's built-in Auth::user().
You can create a custom driver by implementing a getAuth() method that returns a User instance. and you can update the newly created driver in auth_driver field in the config.php
Migrations
The package provides migrations for:
Logging
Both commands (xetreon:permissions and xetreon:seedRole) log actions using Laravel's default logging system (Log::info()).
Exception Handling
By default, permission failure return false. If is false, checkRole() simply returns false. If you want to throws the exception defined in permission_exception config, set as true
Notes
-
Super Admin automatically bypasses all permission checks if is true.
-
Always run php artisan xetreon:permissions after adding new controllers or actions.
- Excluded controllers are ignored during permission generation. For example, if the controller path is
/var/www/project/app/Http/Controllers/v1/Auth/AuthController.php, then you need to addAuth/AuthControllerin the exlude array. No need to add the extension as well.
Example Workflow
- Install package and publish config.
- Run migrations.
- Seed super admin role:
php artisan xetreon:seedRole 1-Generate permissions:php artisan xetreon:permissions -
Assign roles to users:
- Check permissions in controllers using RolePermission trait:
License
MIT License