Tutorial last revisioned on April 10, 2024 with Laravel 11
The term "multi-tenancy" has different meanings and implementations in Laravel. In this article, let's take a look at a multi-database approach, using the package stancl/tenancy: I will show you step-by-step, how to make it work.
This is a text-form excerpt from one of the sections of my 2-hour video course: Laravel Multi-Tenancy: All You Need To Know
Initial Laravel Project
Before starting everything about multi-tenancy, let's set up our project very quickly.
1laravel new project2cd project3composer require laravel/breeze --dev4php artisan breeze:install
This is straightforward: install the Laravel project and then install Laravel Breeze for quick authentication scaffolding.
Next, we will have two basic CRUDs:
- Project (string: name)
- Task (string: name, foreignId: project_id)
You can see wow those CRUDs are set up here in the GitHub repository.

Tenancy Installation and Configuration
We will use the stancl/tenancy package for managing multi-tenancy. Installation is the same as with any other Laravel package:
1composer require stancl/tenancy2php artisan tenancy:install3php artisan migrate
After installing the package, we need to register TenancyServiceProvider in the config/app.php file. After RouteServiceProvider add a line:
config/app.php:
1return [ 2 // 3 'providers' => [ 4 App\Providers\EventServiceProvider::class, 5 App\Providers\RouteServiceProvider::class, 6 App\Providers\TenancyServiceProvider::class, 7 // 8 ], 9 //10];
Next, the package created migration for the Tenant modal, but we need to...
Premium Members Only
This advanced tutorial is available exclusively to Laravel Daily Premium members.
Already a member? Login here
Premium membership includes:
Comments & Discussion
Hello Everyone ! which one should i use for api sanctum or passport in laravel multi tenancy ? below subdomains are user1.domain.com user2.domain.com database is centeral for all users.
Thanks
Hi, there is no single answer for this. Both API authentication methods are different, so without knowing all the specifics.
Here's a few guides to help you make a decision:
https://laraveldaily.com/video/laravel-api-auth-demo-passport-oauth-and-sanctum
https://laraveldaily.com/lesson/laravel-api/authentication-sanctum-passport-jwt
thank you! that is help alot, looking for the same article but using jetstream please.
I think for Jetstream it would be mostly the same, with different Controllers, like
RegisteredUserControllerin Jetstream would probably be Fortify ActionCreateNewUser, from what I remember. But all the other Model/route/middleware structure would be the same as this article.