mardi 24 juillet 2018

Cloud Iplementation with laravel

I have build an application which is not yet a cloud implementation, however i am planing to change its archetecture to have cloud features. I am planing to have one application with every client a different/client specific datatbase. I tried to setup multiple database in config/database.php and set the default connection to my system database. I am planing to have 2 tables in this database, one is users table (for authentication) and client table, for getting the client database information (database name, username, password etc). Once the authentication is done, i will grab the client details and connect to client database, I want all other operations after authentication to happen on that connection. I tried to create a connection on fly using the following code, once authentation is done

DB::disconnect(); /* disconnecting system database connection
and creating a new connection dynamically based on the values i get from 
clients table */

config::set(['database.connections.on_fly' => [
        'driver'    => $params['driver'],
        'host'      => $params['host'],
        'database'  => $params['database'],
        'username'  => $params['username'],
        'password'  => $params['password'],
    ]]);

    Config::set('database.default','on_fly');
    return DB::reconnect();

But this doesnt work for me, since the code works for the current reuest only, once this reuest is done, the system automatically sets the default database back to system. Can anyone suggest me a good approach, or implementation that i can consider to achieve the reuirement.

Thanks in advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire