you can change the the default env variable names, it will not break the functionality of you appication
you can change your database.php to something like this:
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('MYSQL_DB_HOST', 'localhost'),
'port' => env('MYSQL_DB_PORT', '3306'),
'database' => env('MYSQL_DB_DATABASE', 'iranad'),
'username' => env('MYSQL_DB_USERNAME', 'root'),
'password' => env('MYSQL_DB_PASSWORD', 'mysql'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
'mongodb' => [
'driver' => 'mongodb',
'host' => env('MONGO_DB_HOST', 'localhost'),
'port' => env('MONGO_DB_PORT', '27017'),
'database' => env('MONGO_DB_DATABASE'),
'username' => env('MONGO_DB_USERNAME'),
'password' => env('MONGO_DB_PASSWORD'),
'options' => [
'database' => 'admin'
]
],
],
then on the .env define each variable name
#sql
MYSQL_DB_HOST=...
MYSQL_DB_PORT=...
MYSQL_DB_DATABASE=...
MYSQL_DB_USERNAME=...
MYSQL_DB_PASSWORD=...
# mongo
MONGO_DB_HOST=...
MONGO_DB_PORT=...
MONGO_DB_DATABASE=...
MONGO_DB_USERNAME=...
MONGO_DB_PASSWORD=...
on your models define protected connection attribute: this should be either of your connection names you defined on the database.php
protected $connection = 'mongodb';
the only problem for you here would be implementing relations between databases, which is impossible, you will need to write your own queries for that.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community