Multiple database connection using Illuminate/Database Eloquent ORM in CodeIgniter 3
<p>I have just included Laravel's database layer Eloquent to my CodeIgniter 3 project. My problem however is that I can't connect to multiple databases using Eloquent models.</p>

<p>For the default DB, this is how I configured the DB:</p>

<pre><code>$capsule = new Capsule;

$capsule-&gt;addConnection(array(
        'driver'    =&gt; 'mysql',
        'host'      =&gt; "localhost",
        'database'  =&gt; "employees_db",
        'username'  =&gt; "root",
        'password'  =&gt; "",
        'charset'   =&gt; 'utf8',
        'collation' =&gt; 'utf8_unicode_ci',
        'prefix'    =&gt; '',
        ));

$capsule-&gt;setAsGlobal();
$capsule-&gt;bootEloquent();
</code></pre>

<p>The above works well. But I have an employee table from another database. I can use it using query builder, but fails with Eloquent models.</p>

<p>I tried this:</p>

<pre><code>$employees = new Capsule;

$employees-&gt;addConnection(array(
        'driver'    =&gt; 'mysql',
        'host'      =&gt; "host2",
        'database'  =&gt; "employees_db",
        'username'  =&gt; "user",
        'password'  =&gt; "pass",
        'charset'   =&gt; 'utf8',
        'collation' =&gt; 'utf8_unicode_ci',
        'prefix'    =&gt; '',
        ),'employees');

$employees-&gt;setAsGlobal();
</code></pre>

<p>Tried setting up an Eloquent model and using the connection like:</p>

<pre><code>protected $connection = "employees";
</code></pre>

<p>Is it possible to connect to multiple databases using Illuminate\Database Eloquent ORM outside of Laravel? If yes, how?</p>