Support the ongoing development of Laravel.io →
Configuration Database Eloquent
Last updated 1 year ago.
0

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.

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

anonymox anonymox Joined 16 Oct 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.