casbin/laravel-authz
Casbin Laravel Authz brings Casbin's powerful RBAC/ABAC access control to Laravel. Define policies, protect routes with middleware, integrate gates, cache decisions, and manage rules via Artisan commands—all with familiar Laravel conventions.
Architecture fit. laravel-authz is a thin service-provider wrapper around the PHP-Casbin core (php-casbin/php-casbin), which means authorization decisions are computed by an external policy engine rather than by Laravel's native Gate/Policy classes. The model is clean: a declarative model.conf defines the authorization logic (ACL, RBAC, RBAC-with-domains, ABAC matchers), and a policy store (file, database, or cached adapter) holds the rules. The package binds an Enforcer into the service container, exposes a facade, and ships middleware so enforcement can sit in the request pipeline or be called explicitly in controllers/services. For a TPM this is attractive because authorization logic becomes configuration and data rather than application code — policy changes don't require a deploy — and the same mental model works across dozens of endpoints.
The main architectural caveat is coexistence. Laravel already has a first-class authorization system, and this package does not replace it so much as sit alongside it. Running two authorization systems in one codebase is a durable source of bugs and audit findings unless the boundary is drawn deliberately (e.g., Gates for coarse role gating and UI affordances, Casbin for fine-grained, resource-scoped, or attribute-driven decisions). That boundary decision is a design task, not a library task, and it should be made explicitly before adoption rather than discovered later.
Integration feasibility. Low. Installation is a Composer require, a config publish, optionally a migration for the rules table if you use the database adapter, and registering the middleware. There is no invasive refactor required. The real integration work is authoring the model and seeding the policy store from whatever exists today (roles table, hardcoded checks, LDAP groups).
Technical risk.
php-casbin core is the more heavily used artifact and carries most of the technical weight.Key questions to resolve.
Gate (e.g., as a user/ability resolver), or is it strictly parallel?Stack fit. Strong for Laravel monoliths and Laravel-based APIs where authorization requirements are outgrowing hand-written Gates — particularly multi-tenant scoping, hierarchical resources, or rules that product/ops wants to change without engineering involvement. Weak fit for a single-role, three-permission application, where the added concept count is not repaid.
Migration path. Do not rip out Gates. Run Casbin in shadow mode first: evaluate both systems for every guarded action, log disagreements with request context, and let only the existing Gate make the real decision. This produces a discrepancy backlog that doubles as a policy-seeding specification and is the single highest-value risk-reduction step available. Once the disagreement rate is acceptably low on a bounded domain (e.g., document permissions in one product area), flip that domain to Casbin-authoritative, then proceed domain by domain.
Compatibility. Pin both the wrapper and php-casbin core explicitly; treat the pair as one versioned unit. Treat model.conf as code — version-controlled, reviewed, deployed with the app. If the existing schema already encodes roles and permissions, write a one-way exporter into the Casbin policy table rather than pointing Casbin at existing tables with a bespoke adapter; custom adapters are a maintenance liability and hide schema coupling.
Sequencing.
Maintenance. Apache-2.0, permissive, no license friction. The steady-state maintenance burden is not dependency upgrades — those are routine — but policy hygiene: the policy table becomes a production dataset that nobody owns by default. Assign an explicit owner and an access-review cadence from day one, or the authorization store will drift into an unauditable state faster than application code would.
Support. Community-supported through GitHub issues; no SLA. Escalation for a production authorization outage is "read the source." For a system on the critical path of every request, budget internal expertise rather than assuming upstream responsiveness.
Scaling. Enforcement is stateless and horizontally friendly, but every node holds a policy snapshot. Two scaling axes matter: policy size (enforcer load time and memory per worker — benchmark at your realistic rule count, not at demo scale) and policy change rate (cache invalidation fan-out). High rule counts with frequent updates is the combination that hurts.
Failure modes to design for explicitly.
model.conf can deny all traffic or throw on every request. Gate model changes behind the same CI validation you would apply to code, plus a canary deploy.Ramp-up. Casbin's model DSL (matchers, effects, role inheritance semantics) is genuinely unfamiliar to most Laravel developers and is the dominant onboarding cost — realistically one to two weeks to productive, longer to confident. Budget for internal worked examples mapped to your actual domains, a short written standard for authoring policies, and a runbook covering cache flush, policy rollback, and emergency revocation. The operational cost of this package is not in the code you write to adopt it; it is in the governance, tooling, and on-call literacy you must stand up around the policy store afterward.
How can I help you explore Laravel packages today?