Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Rolepermissionmanager Laravel Package

salvatorecervone/rolepermissionmanager

View on GitHub
Deep Wiki
Context7

๐Ÿ›ก๏ธ Laravel Role & Permission Manager

Latest Version on Packagist Total Downloads Software License PHP Version Laravel Version

A modern, dynamic, database-driven Role & Permission Manager for Laravel that completely replaces static middleware annotations with a centralized, zero-hardcoding Access Control Layer (ACL).


๐Ÿ’ก 100% Automatic โ€” Zero Code Changes & Coexistence

In traditional authorization setups, permissions are hardcoded into route definitions, controller constructors, or method calls:

// โŒ Hardcoded permissions in code
Route::delete('/invoices/{id}', [InvoiceController::class, 'destroy'])
    ->middleware('permission:delete-invoices');

When business rules change, developers must edit controllers, routes, commit, and deploy.

RolePermissionManager eliminates this entirely:

  • โšก Zero Code Modifications โ€” No need to add traits, modify controllers, or annotate routes.
  • ๐Ÿ›ก๏ธ Coexists with Existing Systems โ€” No need to remove or refactor your existing roles, permissions, or database tables. RolePermissionManager uses isolated tables (acl_*) and a non-intrusive dynamic interceptor.
  • ๐ŸŒ Instant Runtime Updates โ€” Change any permission rule from the built-in Web Admin Panel in seconds with zero code changes and zero downtime.

โœจ Features

  • ๐Ÿš€ Zero Hardcoding โ€” Define clean routes without cluttering them with permission:... middleware
  • ๐Ÿ” Route Auto-Discovery โ€” php artisan acl:sync scans your routes and registers new endpoints automatically
  • ๐Ÿ“ฆ Custom Resources Support โ€” Create, manage, and protect arbitrary classes, methods, services, or UI actions from the panel
  • ๐Ÿ”ฒ Interactive Role-Permission Matrix โ€” Spreadsheet-style pivot matrix (/acl-admin/matrix) with real-time AJAX permission toggling
  • ๐Ÿ” Access Simulator & Diagnostic Tester โ€” Test user authorization step-by-step from both the UI (/acl-admin/simulator) and CLI (php artisan acl:check)
  • ๐Ÿ’พ JSON Export & Import โ€” Seamlessly transfer entire ACL configurations across environments (Local โž” Staging โž” Production) via web UI or CLI (php artisan acl:export/acl:import)
  • โšก Bulk Actions on Routes & Resources โ€” Mass-assign permissions, set Super Admin only flags, or change visibility with one click
  • ๐Ÿ“œ Audit Trail & Activity Log โ€” Complete history tracking of who changed which role, permission, or route (/acl-admin/audit-logs)
  • โฐ Automated Scheduler โ€” Configurable daily route synchronization to catch new endpoints
  • ๐Ÿ›ก๏ธ Single Dynamic Interceptor โ€” DynamicAclGuard middleware evaluates requests against cached ACL rules
  • โšก High Performance & Low Latency โ€” Complete cache layer (Redis/File/Memory) with automatic invalidation on Eloquent events (0 DB queries per request)
  • ๐ŸŽ›๏ธ AND / OR Permission Operators โ€” Choose whether a resource requires all or at least one of the linked permissions
  • ๐Ÿ‘‘ Super Admin Bypass & Dedicated Protection โ€” Configurable super admin role that bypasses checks, plus a single-click toggle to reserve any route/resource exclusively for Super Admins
  • ๐Ÿ‘ค User Access Management โ€” Manage user roles and direct permissions with multi-column display support (e.g. ['name', 'cognome']) and live autocomplete
  • ๐ŸŽจ Blade Directives โ€” @role, @haspermission, @canRoute, and @canResource for views
  • ๐Ÿ”Œ Native Laravel Gate Integration โ€” Works seamlessly with $user->can() and @can
  • ๐Ÿ“ฆ Polymorphic Architecture โ€” Works with any Authenticatable model (User, Admin, Member, etc.)

๐Ÿ“‹ Requirements

  • PHP: ^8.2
  • Laravel: ^10.0 | ^11.0 | ^12.0

๐Ÿ“ฆ Installation

1. Require the package via Composer

composer require salvatorecervone/rolepermissionmanager

2. Publish Assets

You can publish all assets at once:

php artisan vendor:publish --provider="SalvatoreCervone\RolePermissionManager\RolePermissionManagerServiceProvider"

Or publish individual components using specific tags:

Component Publish Command Target Location
Config (Required) php artisan vendor:publish --tag=rolepermissionmanager-config config/rolepermissionmanager.php
Migrations (Required) php artisan vendor:publish --tag=rolepermissionmanager-migrations database/migrations/
Language Files (Optional) php artisan vendor:publish --tag=rolepermissionmanager-lang lang/vendor/acl/
Blade Views (Optional) php artisan vendor:publish --tag=rolepermissionmanager-views resources/views/vendor/acl/
Routes (Optional) php artisan vendor:publish --tag=rolepermissionmanager-routes routes/acl-web.php & routes/acl-api.php

3. Run Database Migrations

php artisan migrate

This creates 8 tables (customizable in config):

  • acl_roles
  • acl_permissions
  • acl_secured_resources
  • acl_scanner_rules (dynamic route exclusions & inclusions)
  • acl_model_has_roles (polymorphic pivot)
  • acl_model_has_permissions (polymorphic pivot)
  • acl_role_has_permissions (pivot)
  • acl_permission_has_resources (pivot)
  • acl_audit_logs (audit history)

๐Ÿš€ Quick Start

1. (Optional) Add the Trait to your User Model

Adding HasAcl to your User model is optional โ€” it provides direct convenience helper methods on the user instance (e.g., $user->assignRole(), $user->hasPermission(), $user->canAccessRoute()):

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use SalvatoreCervone\RolePermissionManager\Traits\HasAcl;

class User extends Authenticatable
{
    use HasAcl;
}

Note: The dynamic middleware DynamicAclGuard, the Admin Panel, and AclRegistry work seamlessly even without modifying your User model.

2. Synchronize Application Routes

php artisan acl:sync --notify

Output:

๐Ÿ” Scanning routes...
+-----------------------+--------+----------------------+------------------------------------------------+
| Identifier            | Method | URI                  | Action                                         |
+-----------------------+--------+----------------------+------------------------------------------------+
| dashboard             | GET    | /dashboard           | App\Http\Controllers\DashboardController@index |
| invoices.index        | GET    | /invoices            | App\Http\Controllers\InvoiceController@index   |
| invoices.create       | GET    | /invoices/create     | App\Http\Controllers\InvoiceController@create  |
| invoices.store        | POST   | /invoices            | App\Http\Controllers\InvoiceController@store   |
| invoices.destroy      | DELETE | /invoices/{id}       | App\Http\Controllers\InvoiceController@destroy |
+-----------------------+--------+----------------------+------------------------------------------------+
โœ” Discovered 5 new routes. Cache refreshed.

3. Open the Web Admin Panel

Navigate to https://your-domain.com/acl-admin (protected by ['web', 'auth'] middleware by default).

From the panel you can:

  • ๐Ÿ”ฒ Role-Permission Matrix (/acl-admin/matrix): Toggle permissions per role in real time.
  • ๐Ÿ” Access Simulator (/acl-admin/simulator): Select any User and Route to run real-time authorization diagnostics.
  • โšก Bulk Actions (/acl-admin/routes): Select multiple routes to apply permissions or Super Admin flags in bulk.
  • ๐Ÿ’พ Export & Import (/acl-admin/export-import): Download JSON backups or import ACL settings from other environments.
  • ๐Ÿ“œ Audit Logs (/acl-admin/audit-logs): Review full historical tracking of authorization changes.
  • ๐Ÿ‘ค Users & Access (/acl-admin/users): Assign roles and direct permissions to users with multi-model polymorphic support.

4. ๐Ÿ‘ฅ Multi-Model / Polymorphic Support (Optional)

If your application has multiple authenticatable models (e.g. User, Admin, Staff), configure user_models in config/rolepermissionmanager.php:

'user_models' => [
    'users' => [
        'label'             => 'Users',
        'model'             => App\Models\User::class,
        'searchable_fields' => ['name', 'email'],
        'display_field'     => ['name', 'cognome'],
        'secondary_field'   => 'email',
    ],
    'admins' => [
        'label'             => 'Administrators',
        'model'             => App\Models\Admin::class,
        'searchable_fields' => ['nome', 'cognome', 'email'],
        'display_field'     => ['nome', 'cognome'],
        'secondary_field'   => 'email',
    ],
],

The Web Admin Panel will automatically render model selector tabs on /acl-admin/users and within the Access Simulator!

  • โš™๏ธ Scanner Rules (/acl-admin/scanner-rules): Manage route exclusions and auto-registration patterns.

๐Ÿ› ๏ธ Artisan Commands

# 1. Route Synchronization
php artisan acl:sync                                         # Basic route scan and cache rebuild
php artisan acl:sync --clean                                 # Remove deprecated routes from DB
php artisan acl:sync --auto-permissions                      # Auto-create permissions for new routes
php artisan acl:sync --clean --auto-permissions --notify     # Complete sync with verbose log

# 2. Access Diagnostics & Simulation
php artisan acl:check 1 invoices.destroy                     # Check user ID 1 against a route
php artisan acl:check [email protected] "CorsoController@dettagliocorsi"

# 3. Export & Import Configuration
php artisan acl:export                                       # Export to storage/app/acl-export-*.json
php artisan acl:export --path=/path/to/custom-backup.json
php artisan acl:import /path/to/acl-export.json              # Merge configuration
php artisan acl:import /path/to/acl-export.json --overwrite  # Overwrite existing associations

๐ŸŽจ Blade Directives

{{-- 1. Check Role --}}
@role('admin')
    <a href="/admin/settings">Admin Settings</a>
@endrole

{{-- 2. Check Permission (Direct or via Role) --}}
@haspermission('invoices.export')
    <button>Export CSV</button>
@endhaspermission

{{-- 3. Check Route Access --}}
@canRoute('invoices.destroy')
    <button class="btn-delete">Delete Invoice</button>
@endcanRoute

{{-- 4. Check Custom Resource Access --}}
@canResource('CorsoController@dettagliocorsi')
    <button class="btn-info">View Details</button>
@endcanResource

โš™๏ธ Configuration Reference

Key settings in config/rolepermissionmanager.php:

return [

    // User Model & Search Configuration
    'users' => [
        'table'             => 'users',
        'searchable_fields' => ['name', 'cognome', 'email'],
        
        // Single column or array of columns concatenated with space:
        'display_field'     => ['name', 'cognome'],           // e.g. "Mario Rossi"
        'secondary_field'   => ['matricola', 'email'],        // e.g. "MAT12345 [email protected]"
        'per_page'          => 25,
    ],

    // Super Admin Settings & Bypass
    'super_admin' => [
        'role'       => 'super-admin', // Role slug or null to disable
        'all_access' => true,          // true / 'all' for full bypass, false/null to require explicit permissions
    ],

    // Middleware settings
    'middleware' => [
        'register_globally'    => true,    // Applied to 'web' and 'api' groups
        'guard'                => null,    // null = default guard
        'unprotected_behavior' => 'allow', // 'allow' or 'deny'
    ],

    // Automated Scheduler
    'scheduler' => [
        'enabled' => false,
        'time'    => '06:00',
        'options' => [
            'clean'            => false,
            'auto_permissions' => false,
            'notify'           => true,
        ],
    ],

    // Web Admin Panel
    'admin_panel' => [
        'enabled'    => true,
        'prefix'     => 'acl-admin',
        'middleware' => ['web', 'auth'],
        'page_title' => 'ACL Manager',
        'per_page'   => 25,
    ],

];

๐Ÿงช Testing & Standalone Preview

Run the test suite:

composer test
# or
./vendor/bin/phpunit

Standalone Workbench Preview (No full app required!)

# 1. Run migrations and seed demo data
php vendor/bin/testbench migrate:fresh --seed --class="Workbench\Database\Seeders\DatabaseSeeder"

# 2. Start the local server
php vendor/bin/testbench serve --port=8080

Open http://127.0.0.1:8080 and log in with:


๐Ÿ“„ License

The MIT License (MIT). Please see LICENSE for more information.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel