Spatie multitenancy. php: <?php use laravel-multitenancy At the start of each request, the package will try to determine which tenant should be active for the current request. To use that tenant finder, specify its class name in the tenant_finder key of the multitenancy config file. Configuring the database connections When using a separate database for each tenant, your Laravel app needs two database connections. This is done by a TenantFinder. 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. Feb 10, 2026 · README Unopinionated multitenancy package for Laravel This package can make a Laravel app tenant aware. The package can determine which tenant should be the current tenant for the request. com/spatie/laravel-multitenancy/issues/124), so you would need to create them manually. 0 Removed UsesTenantModel trait Remove any reference to our old trait Spatie\Models\Concerns\UsesTenantModel, because now the right . The first step to reach our goal is upgrading our package version. Embrace multi-tenancy to enhance your application’s architecture and user experience. laravel-multitenancy Before using the following instructions, make sure you have performed the base installation steps first. Only use the instructions on this page if you want each of your tenants to have their own database. Jobs that should be tenant aware should implement the empty marker interface Spatie\Multitenancy\Jobs\TenantAware or should be added to the config tenant_aware_jobs. // in multitenancy. Oct 16, 2025 · This walkthrough shows a pragmatic, production-friendly approach to multi-tenant authorization using Spatie’s multitenancy package plus Spatie’s permission package. You’ll learn how to Jul 11, 2025 · This document provides a comprehensive overview of the spatie/laravel-multitenancy package, explaining its philosophy, architecture, and core systems. Migrating the database With the database connection set up, we can migrate the landlord database. The philosophy of this package is that it should only provide the bare essentials to enable multitenancy. The package ships with a DomainTenantFinder that will make the tenant active whose domain attribute value matches the host of the current request. First, you must publish and run the migration: php artisan vendor:publish --provider="Spatie laravel-multitenancy This package can be installed via composer: composer require spatie/laravel-multitenancy Publishing the config file You must publish the config file: php artisan vendor:publish --provider="Spatie\Multitenancy\MultitenancyServiceProvider" --tag="multitenancy-config" This is the default content of the config file that will be published at config/multitenancy. This package enables Laravel applications to serve multiple tenants through a flexible, unopinionated approach to multitenancy. This package can make a Laravel app tenant aware. // in laravel-multitenancy On this page Option 1: extending the Option 2: using a model of your own Performing actions when a tenant gets created laravel-multitenancy Docs Laravel-multitenancy Using-tasks-to-prepare-the-environment Creating your own task 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. The platform uses a landlord/tenant database split powered by Spatie Laravel Multitenancy: Landlord database — users, organizations, organization memberships, tenant database records, platform event store The Spatie\Multitenancy\Tasks\SwitchDatabaseTask can switch the configured database name of the tenant database connection. The package contains a lot of niceties such as making queued jobs tenant aware, making an artisan command run for each tenant, an easy way to set a connection on a model, and much more. php Although spatie/laravel-multitenancy supporting single databases, it doesn't come with query scopes (and seems like there are no plans to add them, as you can see here: https://github. laravel-multitenancy Per request, the package can determine the "current" tenant. composer require spatie/laravel-multitenancy:^4. The key philosophy of this package is that it should provide only the bare essentials to enable multi-tenancy and to make your application tenant aware. In the multitenancy config file, you specify the tenant finder in the tenant_finder key. laravel-multitenancy In the 4. The database name used will be in the database attribute of the Tenant model. By following the steps and best practices outlined in this article, you can create scalable, secure, and maintainable applications. Only use the instructions on this page if you want to use one database. It has a name of spatie/laravel-multitenancy and has a slightly different philosophy than others. One named landlord, which points to laravel-multitenancy Before using the following instructions, make sure you have performed the base installation steps first. x version, we have introduced the contract concept to the Tenant so that any model could implement the interface. Mar 23, 2025 · Conclusions Implementing multi-tenancy in Laravel with the Spatie package offers a robust solution for managing multiple tenants efficiently. Are you a visual learner? Then watch this video that covers how you can use laravel-multitenancy and how it works under the hood. l7fm, ybwlud, mvw3y, x3lvl, okgbq, o5ek0l, e0yk, adssx, 1rjf7o, bqtmq,