Spatie multi tenancy. Embrace multi-tenancy to enhance your application’s architect...
Spatie multi tenancy. Embrace multi-tenancy to enhance your application’s architecture and user experience. This package can make a Laravel app tenant aware. By following the steps and best practices outlined in this article, you can create scalable, secure, and maintainable applications. Automatically determining the current tenant At the start of each request, the package will try to determine which tenant should be active for the current request. Make your Laravel app usable by multiple tenants. The philosophy of this package is that it should only provide the bare essentials to enable multitenancy. Feb 2, 2026 · A comprehensive guide to implementing multi-tenancy in Laravel applications using the Spatie package, covering tenant identification, database isolation strategies, asset separation, and production deployment patterns. To use that tenant finder, specify its class name in the tenant_finder key of the multitenancy config file. Embrace the power of Laravel and Spatie’s package to take your SaaS . See the steps and examples for laravel-activitylog, laravel-permission, laravel-medialibrary and laravel-login-link. You should Here is an example implementation where we are going to use a prefix when a tenant is current, and clear out that prefix when forgetting the tenant. Mar 23, 2025 · Conclusions Implementing multi-tenancy in Laravel with the Spatie package offers a robust solution for managing multiple tenants efficiently. Contribute to spatie/laravel-multitenancy development by creating an account on GitHub. namespace Spatie\Multitenancy\Tasks; If a tenant aware job is unable to retrieve the tenant, because the tenant was deleted before the job was processed, for example, the job will fail with an instance of Spatie\Multitenancy\Exceptions\CurrentTenantCouldNotBeDeterminedInTenantAwareJob. There are two ways of doing this by extending the Tenant model provided by the package, or by prepping a model of your own. When a tenant is made the current one, the package will run the makeCurrent method of all tasks configured in the switch_tenant_tasks key of the multitenancy config file. Jan 26, 2023 · Multi-tenancy is a software architecture in which a single instance of a software application serves multiple customers, known as “tenants”. Per request, the package can determine the "current" tenant. If you want to change or add behaviour on the Tenant model you can use your custom model. Jul 20, 2021 · How to use spatie / laravel-multitenancy with single database? Ask Question Asked 4 years, 7 months ago Modified 4 years, 6 months ago May 26, 2020 · Spatie released a new offering for Laravel apps with an unopinionated multitenancy package to make apps tenant-aware. Protecting against cross tenant abuse To prevent users from a tenant abusing their session to access another tenant, you must use the Spatie\Multitenancy\Http\Middleware\EnsureValidTenantSession middleware on all tenant-aware routes. By following the best practices and strategies outlined in this article, you can ensure your application is robust, maintainable, and ready to grow with your user base. The package ships with a class named DomainTenantFinder that will try to find a Tenant whose domain attribute matches with the hostname of the current request. Each tenant has access to a dedicated and isolated portion of the application, with the ability to customize and configure the application to meet their specific needs. Learn how to use Spatie packages with Tenancy for Laravel, a multi-tenancy solution for Laravel applications. Jan 26, 2023 · The main goal of a data storage strategy in a multi-tenant system is to ensure that each tenant’s data is isolated and secure, while simultaneously providing an efficient and scalable solution Mar 23, 2025 · Implementing multi-tenancy in Laravel with the Spatie package offers a robust solution for managing multiple tenants efficiently. The package ships with a DomainTenantFinder that will make the tenant active whose domain attribute value matches the host of the current request. This is done by a TenantFinder. Then watch this video that covers how you can use laravel-multitenancy and how it works under the hood. Mar 23, 2025 · Conclusions Building a multi-tenant SaaS application in Laravel with Spatie’s package is a powerful approach to creating scalable and efficient solutions. Jan 30, 2026 · This article explains how Laravel multi-tenancy works with Spatie Permissions, covering architecture decisions, role management, and best practices used in production systems. Option 1: extending the Tenant model provided by the package Make sure that your custom model extends the Spatie\Multitenancy\Models\Tenant model provided by the package. xuuqq rcanh emywrixd kkj qkhq udha shmw mshsxf yajaps xvpr