Support the ongoing development of →
Configuration Database
Last updated 2 years ago.

geocine! Friend, I got to see this post. But not served to me because al the definition of bank is being done via code. I need something automatic. In a way that moving the client, which can be a parameter, it already search the database data connection such as a client and Config :: set the secondary connection. Something like that!

Last updated 2 years ago.

You can create dynamic DB connections in laravel with following syntax

Config::set('database.connections.key', array(
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'dbname',
    'username'  => 'dbuser',
    'password'  => 'dbpass',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',

With that DB::connection('key'); would just work.


Last updated 2 years ago.

Does not have a way to do this in the before filter?

Last updated 2 years ago.

Anyone know where's the error I created this filter to setting a new connection, but not okay by setting ..


Route::filter('defineConnection', function($request) {
if (Session::has('slug_cliente')) { $cliente = Session::get('slug_cliente'); $minutes = 30; $cli = Cache::remember('connection' . $cliente, $minutes, function() use ($cliente) { return DB::connection("admin") ->table("clientes") ->where("code", "=", $cliente) ->first(); }); if (count($_cli)) { //Esse cara aqui eu criaria um "Filter" para usar com before -> "defineConnection" Fazendo essa verifica Config::set("database.conections.cliente.driver", "mysql"); Config::set("", $_cli->host); Config::set("database.conections.cliente.database", $_cli->database); Config::set("database.conections.cliente.user", $_cli->username); Config::set("database.conections.cliente.password", $_cli->password); Config::set("database.default", "cliente"); } else { return Redirect::to("/"); } } else { return Redirect::to("/"); } });



Route::get('login/{slug_cliente?}', function($slug_cliente = NULL) {
if (is_null($slug_cliente)) { return Redirect::to("/"); } //Se for Nulo, redireciona para "/" sem logar. Session::put('slug_cliente', $slug_cliente); return View::make("login"); });

Route::post('login/{slug_cliente}', array('before' => 'defineConnection', function($slug_cliente = null) {

    $credentials = array(
        'email' => Input::get("email"),
        'password' => Input::get("password"),
    $user = Sentry::authenticate($credentials, false);
    if (!$user) {
        return Redirect::to("dashboard");
    } else {
        return Redirect::back();
Last updated 2 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.