A package that fits your needs
stancl/tenancy is a flexible multi-tenancy Laravel package that comes with lots of features out-of-the-box and doesn't stand in your way when you need anything custom.
Instead of forcing you to change how you write your code, the package by default bootstraps tenancy automatically, in the background. Database connections are switched, caches are separated, filesystems are prefixed, etc.
Automatic data separation
Out of the box, the package makes the following things tenant-aware: databases, caches, filesystems, queues, redis stores. This means that if you've already written your app and are looking to make it multi-tenant, you don't have to change anything!
Integrates with other packages
Since the automatic mode changes the default database connection, most other packages will use this connection too. This means that you can do awesome things such as using Laravel Nova inside the tenant application to manage the tenant's resources.
Many other tenancy packages have a terrible track record when it comes to testability. We find that unacceptable. With this package, you can test everything. The central application, the tenant application, and everything in between — including the tenant registration flow.
Version 3 is heavily focused on flexibility, but without sacrificing features. Even though everything is customizable, the defaults will likely suit you for the large part.
All of the tenancy bootstrapping logic, post-tenant-creation logic, and most other things, happen as a result of events firing. You can customize every single bit.
Single or multi-database tenancy
Don't want to use the database-per-tenant approach? No problem, we provide you with model traits for scoping models to the current tenant, including models that aren't related to the tenant directly.
Prefer specifying database connections instead of changing the default connection? No problem, we have model traits prepared.
Packed with features
This package has the most features out of all multi-tenancy packages for Laravel.
Shared users between tenants
Need to use the database-per-tenant approach but also need to have users that belong to multiple tenants? We've got you covered. Our Resource Syncing feature lets you synchronize any database resources between specific tenants' databases.
Want to impersonate a user inside a tenant's database from the central context? Or even from another tenant's context? Just enable the user impersonation feature in the config.
Works with any database
Need to separate tenant databases on MySQL/PostgreSQL/SQLite? No problem. Or maybe you want to use PostgreSQL schemas instead? We can do that too.
Trusted by developers
This package powers many production applications on many different hosting platforms.
- Stars on GitHub
- 90 000+
- Sponsors <3
“Tenancy for Laravel allowed us to effortlessly and quickly integrate the needed landlord/tenant functionality for our SaaS platform. It fits our needs perfectly.”
“This package enabled us to abstract all the context switching to focus our development efforts elsewhere. That resulted in significant performance increase. The event driven architecture is powerful, flexible and bends to all our needs.”
Want updates about big releases and product launches?
Sign up for our newsletter.
Frequently asked questions
Yes! The package is in its third major version and has been stable since February 2019. Many people are using it in production.
No, the package supports multi-database tenancy as well as single-database tenancy. For multi-database tenancy, it comes with classes for managing MySQL/SQLite/PostgreSQL databases or schemas and for single-database tenancy it comes with model scopes and traits.
Yes! Version 3 is focused heavily on flexibility. The package comes with great defaults for bootstrapping tenancy automatically based on domains, but if you need to customize anything, or add any behavior — you can do that very easily.
Yes! You can use Nova both to manage tenants and to manage resources inside tenant databases.
Likely yes. The automatic mode of tenancy integrates perfectly with 99% of packages with little to no code changes required.
Yes, many people are using the package on Vapor and reported no issues at all.