Tenancy for Laravel bootstraps tenant context without rewriting app code. It separates databases, cache, filesystems, and queues by domain.
Overview
stancl/tenancy is a Laravel package that turns an existing Laravel application into a multi-tenant SaaS-style system. By default it bootstraps tenancy in the background: database connections switch, caches are isolated, filesystem paths are prefixed, and queues become tenant-aware without replacing core Laravel classes.
Tenants are identified by hostname, including second-level domains. You can use one database per tenant or a single database with model scoping traits. Manual mode lets you wire explicit connections instead of changing the default connection. Bootstrapping, tenant creation, and related behavior are driven by events you can customize.
The package integrates with other Laravel ecosystem tools because automatic mode changes the default connection most packages already use. Documentation describes using Laravel Nova against tenant resources and running tests for central, tenant, and registration flows.
Additional features include resource syncing between tenant databases, user impersonation across tenant contexts, and helpers to create tenant databases on MySQL, PostgreSQL, or SQLite, including PostgreSQL schema separation. Shared users across tenants are supported through resource syncing configuration.
Key features
- Automatic tenant bootstrapping by domain
- Single or multi-database tenancy
- Event-driven customization
- Tenant-aware cache and filesystem
- Queue and Redis isolation
- Resource sync between tenants
- User impersonation across tenants
- Manual connection mode with traits
Use cases
- SaaS apps on standard Laravel code
- Per-tenant databases or schemas
- Admin tools on tenant data
- Testing multi-tenant registration flows