Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Tenancy Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Automatic multi-tenancy for your Laravel application.

Frequently asked questions about Tenancy
How does stancl/tenancy handle tenant identification in Laravel? Does it support subdomains like tenant1.example.com?
The package uses hostname-based tenant resolution by default, including second-level domains (e.g., tenant1.example.com). You can also configure it for path-based routing (e.g., example.com/tenant1) or custom logic via middleware. The resolver is highly flexible and integrates seamlessly with Laravel’s routing system.
Will I need to modify my existing Laravel models or queries to use stancl/tenancy?
No code changes are required in your models or queries. The package automatically switches database connections, cache, and storage contexts per tenant using Laravel’s middleware stack. Your existing Eloquent queries and model logic remain unchanged.
Does stancl/tenancy work with Laravel 13, or is it limited to older versions?
The package is actively maintained for Laravel 10–13 and PHP 8+. It’s fully compatible with the latest Laravel releases, including Laravel 13, with regular updates and CI testing. Check the [GitHub Actions](https://github.com/stancl/tenancy/actions) for the latest compatibility status.
How does tenant isolation work for database connections? Does it support PostgreSQL or only MySQL?
stancl/tenancy supports database-per-tenant isolation for MySQL, PostgreSQL, SQLite, and MariaDB. Each tenant gets its own schema (or database) by default, with transparent connection switching. For PostgreSQL, ensure your `search_path` is configured correctly, as the package handles schema management automatically.
Can I use stancl/tenancy with shared tables (e.g., a global 'users' table) alongside tenant-specific data?
Yes, you can explicitly mark tables as tenant-agnostic using `central_connection()`. For example, a shared `users` table can be accessed without tenant context while other tables remain isolated. This is useful for cross-tenant features like authentication or billing.
How does stancl/tenancy handle background jobs (queues) in Laravel? Will tenant context persist in queued jobs?
The package includes a `QueueTenancyBootstrapper` to ensure tenant context is preserved in background jobs. However, queue workers must be bootstrapped explicitly to avoid running in the central context. This is critical for async workflows like notifications or reports tied to specific tenants.
What’s the performance impact of using stancl/tenancy in production? Should I expect significant latency?
Tenant resolution adds minimal overhead (~1–5ms per request, depending on resolver complexity). For high-traffic apps (e.g., 10K+ RPS), cache the resolver (e.g., `tenant-resolver:cache`) and test under load with tools like k6. Database connection switching is the primary bottleneck, so monitor query performance in multi-tenant setups.
How do I migrate tenant databases without downtime? Does stancl/tenancy support zero-downtime deployments?
The `migrate-fresh` command drops and recreates tenant schemas, which is destructive. For zero-downtime deployments, migrate tenant databases independently or use Laravel’s `migrate` command per tenant. Avoid `migrate-fresh` in production unless you’re prepared for downtime or have backups.
Can I use stancl/tenancy with Laravel Vite for tenant-specific assets (e.g., CSS/JS)?
Yes, the package includes a `TenantAssetsController` to serve tenant-specific assets via Vite or filesystem storage. Configure it in your `routes/tenants.php` to isolate static files (e.g., tenant-branded CSS/JS) without manual path handling. Works alongside Laravel Mix or Vite’s asset pipeline.
Are there alternatives to stancl/tenancy for Laravel multi-tenancy? When would I choose another package?
Alternatives include `spatie/laravel-multitenancy` (shared schema with tenant_id) or `beberlei/doctrineextensions` (Doctrine-based). Choose stancl/tenancy if you need strict database isolation (e.g., SaaS with compliance requirements) and minimal code changes. Use shared-schema solutions if you prefer simpler setups or lower database costs.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai