I want to combine multiple databases in my system. Most of the time the database is MySQL; but it may differ in future i.e. Admin can generate such a reports which is use source of heterogeneous database system.
So my question is does Laravel provide any Facade to deal with such situations? Or any other framework have more suitable capabilities for problem is?
Using
.env
>= 5.0 (tested on 5.5)In
.env
In
config/database.php
Without
.env
<5.0Define Connections
Schema
To specify which connection to use, simply run the
connection()
methodQuery Builder
Eloquent
Set the
$connection
variable in your modelYou can also define the connection at runtime via the
setConnection
method or theon
static method:From Laravel Docs
Using Multiple Database Connections
When using multiple connections, you may access each
connection
via the connection method on theDB
facade. Thename
passed to theconnection
method should correspond to one of the connections listed in yourconfig/database.php
configuration file:You may also access the raw, underlying PDO instance using the getPdo method on a connection instance:
Useful Links
laracasts.com
tutsnare.com
fideloper.com