bonnier/role-provider
Laravel package that provides roles via a provider layer, helping define, expose, and resolve user roles in your app. Intended for simple role handling and integration points where a central role source is needed.
auth). It extends Laravel’s default User model with role capabilities, making it suitable for applications requiring hierarchical permissions (e.g., admin, editor, user).User model), reducing development time for basic RBAC needs.RoleMiddleware) simplifies route/controller-level access control (e.g., @role('admin')).roles table; applications with nuanced permission structures (e.g., Spatie’s permission package) may need significant refactoring.spatie/laravel-permission)?Gate) or is it middleware-only?N+1 issues possible in nested role scenarios?Gate/Policy instead).User model extension).RoleMiddleware).@role, @cannot).php artisan vendor:publish --provider="Bonnier\RoleProvider\RoleServiceProvider"
User model:
use Bonnier\RoleProvider\Traits\HasRoles;
class User extends Authenticatable { use HasRoles; }
php artisan migrate
@role directives.auth:admin) to RoleMiddleware.user->assignRole()).Gate system.| Component | Compatibility Risk | Mitigation |
|---|---|---|
| Laravel Version | Likely incompatible with v10+ | Test with Laravel 9.x; patch if critical. |
| PHP Version | May lack support for PHP 8.1+ features | Use strict_types=1 checks; avoid new syntax. |
| Database | Assumes basic roles table |
Customize migrations if schema differs. |
| Caching | No built-in caching for role checks | Add Cache::remember wrappers manually. |
| Third-Party Packages | Potential conflicts with other auth packages | Isolate in a feature branch; test thoroughly. |
@role directives.403 Forbidden spikes).N+1 issues; mitigate with eager loading:
$user->load('roles'); // In controllers/services
Cache::remember("user-roles-{$user->id}", now()->addHours(1), fn() => $user->roles);
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package incompatibility with Laravel 10+ | Breaking changes in auth system | Test in staging; roll back if critical. |
| Role assignment race conditions | Inconsistent permissions | Use database transactions for role updates. |
| Missing role hierarchy logic | Over-permissive or under-permissive access | Implement custom logic or |
How can I help you explore Laravel packages today?