Configuration
Publish the config file:
scripts/artisan.sh vendor:publish --tag=multiple-databases-config
Edit config/multiple-databases.php and create one entry per additional database (i.e. excluding the default database):
'databases' => [
// Connection:
'mysql' => [
// Database:
'example' => env('DB_DATABASE_EXAMPLE', 'example'),
],
],
Then create the equivalent rows in .env, .env.example, .env.testing and .env.testing.example:
DB_DATABASE_EXAMPLE='example'
The purpose of this is to ensure the database names are not hard-coded anywhere - they can be different on development, staging and live, and you can run integration tests against them.
Make sure the MySQL user has permission to read/write all of the databases (as required).