stancl/tenancy
Automatic multi-tenancy for Laravel with minimal code changes. Supports tenant identification by hostname (including second-level domains) and avoids swapping core classes or adding model traits. Ideal for SaaS apps needing seamless tenant isolation.
queue:retry), critical for async workflows.stancl/tenancy?.env overrides) be managed?Cache::tags()) work out-of-the-box.QueueTenancyBootstrapper.tenant1.app/assets/).Tenancy::impersonate()).| Phase | Tasks | Tools/Commands |
|---|---|---|
| Pre-Migration | Audit existing tenancy logic (shared tables, custom DB connections). | php artisan tenancy:check (custom script) |
| Setup | Install package, configure tenants table, and middleware. |
composer require stancl/tenancy, php artisan vendor:publish --provider="Stancl\Tenancy\TenancyServiceProvider" |
| Data Migration | Migrate existing tenant data to isolated schemas/databases. | Custom scripts or tenancy:migrate-fresh (with --step flag for safety). |
| Code Adaptation | Update tenant-aware logic (e.g., queries, jobs) to use Tenancy::tenant(). |
IDE refactoring tools, manual review. |
| Testing | Validate tenant isolation, impersonation, and edge cases (e.g., queue jobs). | php artisan tenancy:test (custom), PHPUnit. |
| Go-Live | Deploy with feature flags for tenant routing (e.g., DNS changes). | Canary releases, monitoring. |
tenancy:assetPathResolver for tenant-specific asset paths.Tenant model for tenant-specific logic.stancl/tenancy; existing tenants remain on legacy system.Tenancy::disable() for emergency fallbacks.stancl/tenancy for Laravel version support (e.g., v3.10.0 added L13 support).php artisan tenancy:create).PathTenantResolver).QueueTenancyBootstrapper is registered (fixed in v3.5.0+).tenant1.app/assets/).Tenancy::tenant() to inspect current tenant.Tenancy::impersonate() for admin access.php artisan tenancy:list to audit tenants.Cache::remember).pgsql:pool for PostgreSQL).tenant1.us.db, tenant1.eu.db).| Scenario | Impact | Mitigation
How can I help you explore Laravel packages today?