Weave Code
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
Laravel Role Permission

Laravel Role Permission Laravel Package

abdul/laravel-role-permission

Laravel package for simple role-based access control. Generates permissions from your routes, lets you assign them to roles via an admin panel, and protects routes with the auth.role middleware. Includes migrations and an artisan command to register permissions.

View on GitHub
Deep Wiki
Context7

Laravel routes permission configurable from backend

Frequently asked questions about Laravel Role Permission
How does this package generate permissions from my Laravel routes?
The package scans your route definitions and automatically creates permission records for each route protected by the `auth.role` middleware. You then assign these permissions to roles via the admin panel. Run `php artisan permissions:generate` to populate the permissions table.
Can I use this package with Laravel 8/9/10?
Yes, this package supports Laravel 8+ and requires PHP 7.4+. It’s designed to work seamlessly with Laravel’s middleware, gates, and Eloquent ORM, ensuring compatibility with modern Laravel versions.
Does the admin panel allow me to manage roles and permissions dynamically?
Yes, the package includes an admin UI at `/config/role/create` where you can create roles, assign permissions (auto-generated from routes), and manage user-role assignments without touching code.
How do I protect a route with role-based access?
Use the `auth.role` middleware in your route group or individual routes. For example, `Route::middleware(['auth', 'auth.role'])->group(...)` or assign a `role` key in route groups (e.g., `'role' => 'admin'`). The package handles the rest.
Will this package work with custom user or role models?
The package assumes standard Laravel table structures (users, roles, permissions), but you can extend it by publishing and customizing migrations or models. Check the `config/role-permission.php` for configuration options.
Is there a performance impact from dynamic permission checks?
Permission checks add minimal overhead, but for high-traffic routes, consider caching (e.g., Redis) for `Gate::allows()` or middleware. The package doesn’t include caching by default but integrates with Laravel’s caching layer.
Can I assign multiple roles to a single user?
No, this package assigns a single `role_id` to users via the `users` table. For multi-role support, you’d need to extend the package or use a different solution like Spatie’s permission package.
How do I handle role hierarchies (e.g., 'Admin' inherits from 'Editor')?
This package doesn’t natively support role hierarchies. You’d need to implement custom logic (e.g., a `hasParentRole` method) or consider alternatives like Spatie’s package, which offers role inheritance.
What happens if I update my routes after generating permissions?
Run `php artisan permissions:generate` again to sync new or modified routes with the permissions table. The command overwrites existing permissions, so back up your database if needed.
Are there alternatives to this package for Laravel RBAC?
Yes, consider Spatie’s `laravel-permission` (more features, like role hierarchies) or Laravel’s built-in `Gate`/`Policy` system for simpler needs. This package excels in auto-generating route-based permissions with minimal setup.
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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle