roberts/laravel-singledb-tenancy
tenant1.app.com), a common SaaS pattern, but lacks explicit support for path-based routing (e.g., /tenant1).TenantMiddleware) and Eloquent global scopes minimize invasive changes.Route::domain(), Model::boot()). Potential conflicts if custom tenant logic exists in the base application.current_tenant() or using Tenancy::impersonate()).tenant_id).tenant_id on existing tables or handling legacy data requires careful planning.TenantAware trait)?Tenancy::resolve().TenantMiddleware).tenant_id columns).composer require roberts/laravel-singledb-tenancy.php artisan vendor:publish --provider="Roberts\Tenancy\TenancyServiceProvider".tenancy.php (e.g., domain or subdomain resolution).tenant_id to all tenant-scoped tables (use migrations or manual ALTER).tenant_id is indexed: ALTER TABLE users ADD INDEX tenant_id_idx(tenant_id).TenantMiddleware in app/Http/Kernel.php:
protected $middleware = [
\Roberts\Tenancy\Middleware\TenantMiddleware::class,
];
Tenancy::impersonate(Tenant::find(1));
composer.json constraints).roberts/laravel-singledb-tenancy).Tenancy::boot() if not careful.current_tenant() helper.tenant_id for existing data (batch process to avoid locks).Tenancy::debug()).Tenancy::setTenantId()) for critical paths.tenant_id + created_at).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Tenant resolution failure | Data leakage or 500 errors | Configure fallback tenant or graceful degradation. |
| Database connection issues | All tenants affected | Implement circuit breakers for DB layer. |
Missing tenant_id in queries |
Silent data leakage | Use Tenancy::ensureResolved() or CI/CD checks. |
| Concurrent tenant resolution | Race conditions | Use database transactions for critical paths. |
| Package regression | Tenant isolation broken | Fork and maintain if critical. |
Tenancy::impersonate() for debugging.How can I help you explore Laravel packages today?