- 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.