Support the ongoing development of Laravel.io →
Configuration Database
Last updated 1 year ago.
0

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 1 year ago.
0

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.

@source: http://stackoverflow.com/questions/14524181/laravel-4-multiple...

Last updated 1 year ago.
0

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

Last updated 1 year ago.
0

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

filter.php

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("database.conections.cliente.host", $_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.php

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 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.