Tutorial by Examples

Multiple database connections, of any type, can be defined inside the database configuration file (likely app/config/database.php). For instance, to pull data from 2 MySQL databases define them both separately: <?php return array( 'default' => 'mysql', 'connections' => array...
Within the Schema Builder, use the Schema facade with any connection. Run the connection() method to specify which connection to use: Schema::connection('mysql2')->create('some_table', function($table) { $table->increments('id'): });
Similar to Schema Builder, define a connection on the Query Builder: $users = DB::connection('mysql2')->select(...);
There are multiple ways to define which connection to use in the Eloquent models. One way is to set the $connection variable in the model: <?php class SomeModel extends Eloquent { protected $connection = 'mysql2'; } The connection can also be defined at runtime via the setConnect...
Each individual connection can be accessed via the connection method on the DB facade, even when there are multiple connections defined. The name passed to the connection method should correspond to one of the connections listed in the config/database.php configuration file: $users = DB::connection...

Page 1 of 1