Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Multiple DBs: spatie / multi-tenancy

Premium
4:59

Now let's try to perform a multi-database setup with another package spatie/multi-tenancy. I will remind you, it has fewer features. Its philosophy is to provide the bare bones for the multi-tenancy, but not more than that. Again, we start with a project and task CRUD.


Installation and Configuration

First, we start with a package install via composer and publish the configuration.

composer require spatie/laravel-multitenancy
php artisan vendor:publish --provider="Spatie\Multitenancy\MultitenancyServiceProvider" --tag="multitenancy-config"

The next step is choosing the multiple databases.

First, we must configure the database connections. This will slightly differ from the previous package in configuring database connections.

You will need two connections: landlord and tenant. If we look at the config/multitenancy.php, the database connection names are null for tenant and landlord.

config/multitenancy.php:

return [
// ...
 
'tenant_database_connection_name' => null,
'landlord_database_connection_name' => null,
 
// ...
];

We can create a custom connection for the landlord or use...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…