spatie/laravel-multitenancy for Laravel Tenant-Aware Applications
Make your Laravel app usable by multiple tenants
At a glance
- What is it?
- spatie/laravel-multitenancy is a PHP package for adding tenant selection, tenant switching, database separation options, and tenant-aware Laravel behavior. It is intended for teams that want multitenancy support without having the package prescribe a complete application architecture.
- Who is it for?
- Adopt spatie/laravel-multitenancy when a Laravel application needs a small set of tenant-aware behaviors and your team is prepared to define its own tenant model, database policy, and isolation rules. Do not treat it as a complete SaaS platform or as a replacement for an application-specific tenancy design.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 2 days ago.
- What is it written in?
- Mainly PHP, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 7, 2026, and from our analysis. They are not legal advice.
Star history
- spatie/laravel-multitenancy1,375 ★ · +1
| Repository | 2026-10-17 | 2026-11-07 |
|---|---|---|
| spatie/laravel-multitenancy | 1.4k | 1.4k |
1 Stars in the last 21 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
What problem spatie/laravel-multitenancy addresses
spatie/laravel-multitenancy makes an existing Laravel application tenant aware. The package focuses on the mechanics that an application needs after it decides to serve more than one tenant: identifying the current tenant for a request, switching the current tenant, and defining what happens when that switch occurs.
That scope matters. The README describes the package as unopinionated and says it provides the bare essentials rather than a complete tenancy application. It does not present itself as a replacement for decisions about tenant records, domain routing, billing, provisioning, data ownership, or authorization. Those application concerns still need to fit the application's own domain model.
The intended users are Laravel developers building applications that serve multiple tenants and need support for either one database or multiple databases. The package is also relevant to applications where queued work, Artisan commands, or models must behave differently depending on the active tenant. Its documentation points readers to a separate talk about multitenancy strategies before implementation begins, which reflects the design decision that tenancy is broader than a single package installation.
Tenant selection and switching inside Laravel
The core mechanism is tenant resolution for the current request, followed by the ability to switch the current tenant. The README states that the package can determine which tenant should be current for a request and lets the application define behavior when switching to another tenant.
This separation gives Laravel code a point at which tenant-dependent behavior can be coordinated. The application can resolve a tenant before handling domain work, and it can then make the selected tenant available to the parts of the request that need it. The repository includes configuration, source, database, documentation, and test directories, but the README does not document the exact resolver class, tenant interface, configuration keys, or request middleware. Those details should be taken from the linked project documentation rather than inferred from the package name.
The package also includes what the README calls conveniences for tenant-aware queued jobs, running an Artisan command for each tenant, and setting a model connection. These features address places where Laravel normally has a single ambient application context. A queue worker, a console command, and an HTTP request can each need explicit tenant state. The package supplies building blocks for that behavior, while the application remains responsible for deciding when tenant context is valid and when it must be cleared or changed.
Single-database and multiple-database tenancy choices
According to the README, the package supports multitenancy projects using one database or multiple databases. That is a significant design boundary. A shared-database application and a separate-database-per-tenant application have different operational and correctness requirements, even when both use the same tenant selection package.
With one database, tenant separation commonly depends on application logic that keeps records associated with the correct tenant. With multiple databases, connection changes and tenant-specific database availability become part of tenant switching. The README explicitly mentions an easy way to set a connection on a model, but it does not claim that this feature alone enforces isolation, migrates tenant databases, or provisions new tenants.
The package therefore solves the routing and context problem around tenancy, not the entire storage architecture. Teams still need to decide which tables are shared, which records belong to one tenant, how migrations reach each database, and what should happen if a tenant database is unavailable. The documentation's strategy discussion is a better starting point for those decisions than assuming that installing the package produces a finished multi-database system.
Installing spatie/laravel-multitenancy and taking a first step
The README directs users to the documentation site for the complete setup instructions. It does not provide an application installation command, dependency version, configuration publish command, or first-run application example. The package is available through its Packagist listing, and the linked documentation at spatie.be/docs/laravel-multitenancy is the project's stated source for installation and usage details.
The one executable project command documented in the README is the test command. It requires three local MySQL databases, so it is not an application installation step and should not be presented as one. It can be used after the repository has been obtained and its development dependencies are available.
The three databases named by the README are `laravel_mt_landlord`, `laravel_mt_tenant_1`, and `laravel_mt_tenant_2`. Create them before attempting the package test suite, then run the documented command. The expected evidence of a successful first step is that the repository's test command executes against those three databases; the README does not provide a sample command output or a smaller smoke-test application.
After installation, the first application use should follow the linked documentation: define the application's tenant representation, configure how Laravel resolves the current tenant, and decide what switching hooks should do. Those are implementation choices, not values supplied by the README.
Queued jobs, Artisan commands, and model connections
The package's documented conveniences extend tenant awareness beyond ordinary controller requests. The README specifically mentions making queued jobs tenant aware, running an Artisan command for each tenant, and setting a connection on a model.
Each feature targets a separate Laravel execution context. A queued job may run after the original request has ended, so it cannot depend on request-local state that has disappeared. An Artisan command may need to perform work once for every tenant rather than only for the tenant associated with the terminal session. A model connection can vary by tenant when the application uses different database connections. The README's feature list indicates that the package includes mechanisms for these cases, but it does not specify their configuration, callbacks, serialization rules, or exception behavior.
This is useful for applications whose background work must be tenant-scoped. It also creates an adoption responsibility: the application must define which jobs belong to a tenant, how commands select tenants, and how connection failures are handled. The package can provide the Laravel-aware plumbing, but the README does not claim that it can infer tenant ownership from arbitrary queued payloads or repair an incorrectly configured command.
For operators, these features should be reviewed against the chosen Laravel version and the exact release documentation before they are placed in production workflows.
Limitations and alternatives to spatie/laravel-multitenancy
The main limitation is scope. The README explicitly describes an unopinionated package with bare essentials. It does not document a tenant database creation command, automatic provisioning, billing integration, centralized tenant administration, or a complete authorization policy. It also does not explain how to handle deleted tenants, suspended accounts, failed tenant switches, or cross-tenant data access. Those omissions mean an application may need substantial code beyond the package.
The README lists alternatives including `tenancy/tenancy`, `stancl/tenancy`, `gecche/laravel-multidomain`, and `romegadigital/multitenancy`. The README does not compare their internals, so their behavior should not be inferred from this list alone. The practical distinction to investigate is architectural: whether a candidate package supplies a tenant model and provisioning workflow, or whether it also leaves the application responsible for storage topology and tenant lifecycle operations.
spatie/laravel-multitenancy is the wrong choice when the requirement is a complete hosted SaaS control plane rather than tenant-aware Laravel primitives. It may also be a poor fit when a domain-driven design would be clearer with an application-owned tenant abstraction and no package-managed switching behavior.
Maintenance, releases, and the MIT license
The repository is not archived, and the recorded last push is 2026-10-15. The listed recent releases are 4.2.1 on 2026-09-22, 4.2.0 on 2026-08-07, and 4.1.5 on 2026-07-22. These facts indicate recent repository activity in the repository record, but they do not establish compatibility with every Laravel release or guarantee that future changes will fit an application's architecture.
Upgrade planning should include reviewing `CHANGELOG.md` and `UPGRADING.md`, both of which are listed as repository files. The README does not summarize the changes in those files, so it would be inaccurate to claim that an upgrade is routine or that a particular release changes tenant switching. The presence of a migration guide is a reason to check it, not evidence that migration work is unnecessary.
The project is distributed under the MIT License. The README points to `LICENSE.md` for the full license text. This article does not provide legal advice or interpret how the license interacts with a particular commercial deployment. License obligations should be reviewed from that file and, where appropriate, with qualified counsel.
Editorial conclusion
Adopt spatie/laravel-multitenancy when a Laravel application needs a small set of tenant-aware behaviors and your team is prepared to define its own tenant model, database policy, and isolation rules. Do not treat it as a complete SaaS platform or as a replacement for an application-specific tenancy design. Verify first that the documentation and your selected version match the database topology you need, especially when tenants share data or use separate databases. The repository was last pushed on 2026-10-15 and the listed releases include 4.2.1, 4.2.0, and 4.1.5.
Frequently asked questions
What does spatie/laravel-multitenancy do in a Laravel application?
It helps a Laravel application determine the current tenant for a request and switch the current tenant. The README also lists tenant-aware queued jobs, Artisan commands per tenant, and model connection support.
Does spatie/laravel-multitenancy support multiple databases?
Yes. The README says the package works for multitenancy projects that need either one database or multiple databases. It does not claim to automate every part of tenant database provisioning or isolation.
Where are the installation instructions for spatie/laravel-multitenancy?
The README directs users to the project documentation at spatie.be/docs/laravel-multitenancy. The README does not contain the application installation command or configuration commands, so those details should be taken from the linked documentation.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/spatie-laravel-multitenancy)Star history chart for your README
[](https://hysenlabs.com/projects/spatie-laravel-multitenancy)Was this useful?