I want to combine multiple databases in my system. Most of the time the database is MySQL; but it may be different in the future, i.e. administrators can generate reports like this, which is thesource of using heterogeneous database systems.
So my question isDoes Laravel provide any Facadeto handle this situation? Or does any other framework have features that better suit the problem?
In Laravel 5.1, you specify the connection:
By default, Laravel uses the default connection. Pretty simple, isn't it?
Read more here:http://laravel.com/docs/5.1/database#Visit the connection
From the Laravel Documentation: You can access each connection when using multiple connections, through the
DB
connection method on the appearance. The name passed to the connection method should correspond to one of the connections listed in theconfig/database.php
configuration file:Define connection
Use
.env
>= 5.0 (or higher)Use
config/database.php
No
.env
app/config/database.php
Architecture/Migration
Run the
connection()
method to specify the connection to use.Alternatively, define a connection at the top.
Query Builder
model
(In Laravel >= 5.0 (or higher))
Set
in the model$connection
Variableseloquent
(In Laravel
Set
in the model$connection
VariablesTrading Mode
or
You can also define the connection at runtime via the
setConnection
method or theon
static method:Test version (Updated)