laravel-multitenancy-development
Installation
SKILL.md
Laravel Multitenancy Development
When to use this skill
Use this skill when working with multi-tenant Laravel applications using spatie/laravel-multitenancy: determining the current tenant per request, isolating databases or caches per tenant, making queued jobs and artisan commands tenant-aware, or designing landlord/tenant migration strategies.
Core Concepts
- Intentionally minimal: the package resolves a current tenant and runs tasks on switch — it does not add global query scopes or model isolation by itself.
- Current tenant is bound in the IoC container under the key
currentTenantand written to LaravelContextunder the keytenantId. - A
TenantFinderresolves the tenant from the current HTTP request (e.g. by domain). SwitchTenantTaskclasses mutate the environment when a tenant becomes current (switch DB, prefix cache, etc.) and restore it when forgotten.- Models on the landlord DB use
UsesLandlordConnection; models on the tenant DB useUsesTenantConnection.