Skip to main content

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? (30 h 41 min)

You also get:

55 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…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.