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-multitenancyphp 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...