Laravel Change Connection Dynamically : <p>How to change laravel's connection form controller but the connection information stored at database like database manager, my example :</p>

<p>I have a databases information on my database :</p>

<pre><code>id, driver, database_name, username, password, host
</code></pre>

<p>so at my controller just call :</p>

<pre><code>$connection = Database::find( 1 );
$users = new Users();
$users-&gt;setConnection( [
    'driver' =&gt; $connection-&gt;driver,
    'host' =&gt; $connection-&gt;host,
    'username' =&gt; $connection-&gt;username,
    'password' =&gt; $connection-&gt;password
] );
$users = $users-&gt;get();
</code></pre>
