Install database for model?

I am working on a Laravel 4 site that works on multiple databases. For each query that pulls a record from another database, you need to execute one query.

Is there a way to somehow connect this particular model to another database so that I can simply restore it as usual?

$client = Client::find(Session::get('client_id')); 

Any advice is appreciated.

thanks

+7
eloquent laravel laravel-4
source share
1 answer
 // Model class Client extends Eloquent { protected $connection = 'masterDb'; } // config/database.php 'masterDb' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'name', 'username' => 'user', 'password' => 'pass', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ), 

You can create as many name compounds as you like. Set one of them by default, each model can use any of these connections later.

+23
source share

All Articles