silber/bouncer
Bouncer adds roles and abilities to Laravel with a fluent, Eloquent-powered API. Define permissions, assign roles to users, and authorize actions via gates and middleware. Supports caching, scoped abilities, and a simple, expressive permission model.
Gate and Policy systems, offering a flexible approach to authorization.Bouncer::runBeforePolicies()) adds granularity.composer.json constraints align with Bouncer’s supported versions.api, sanctum)? Bouncer supports this, but test thoroughly.scope() and allowEveryone() features.Bouncer::runBeforePolicies().entity_id/entity_type for allowEveryone()).can()/cannot() calls under load. Consider caching strategies (e.g., Bouncer::refresh() for cross-request caching).Gate facade with role/ability checks.auth or custom middleware for route-level permissions.actingAs() + can() assertions).Gate::define('delete_post', ...) with Bouncer::allow($user)->to('delete', Post::class).php artisan vendor:publish --provider="Bouncer\BouncerServiceProvider").allowEveryone(), multi-tenancy).Bouncer facade or HasAbilities trait for models.josephsilber/bouncer:1.0.1).can()/cannot() methods.allowEveryone() for global permissions.Bouncer::refresh()).runBeforePolicies()/runAfterPolicies().composer require josephsilber/bouncer:^1.0 for auto-updates.permissions table.Levels were removed in v1.0.0). Avoid relying on non-public APIs.Bouncer::debug() to inspect role/ability assignments.bouncer:clean Artisan command to reset test data.Bouncer::disableCache()) if permissions change frequently.Bouncer::refresh() to clear cross-request cache.canAny() in loops; it queries all abilities for a user.Bouncer::getAbilities($user).Bouncer::can($user, 'edit', Post::class)) scale well.| Scenario | Risk | Mitigation |
|---|---|---|
| Policy Precedence Misconfig | Bouncer ignores policy denials if running after policies. | Explicitly call Bouncer::runBeforePolicies() if needed. |
| Multi-Tenancy Scope Leak | Global permissions leak into tenant |
How can I help you explore Laravel packages today?