Laravel Multiple DB Connections in Laravel Using Eloquent


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:


class SomeModel extends Eloquent {

    protected $connection = 'mysql2';


The connection can also be defined at runtime via the setConnection method.


class SomeController extends BaseController {

    public function someMethod()
        $someModel = new SomeModel;


        $something = $someModel->find(1);

        return $something;