php - Laravel 5 Changing Database name in controller -


ers. need change database name specific controller. changed database.php

'sqlsrv' => [         'driver'   => 'sqlsrv',         'host'     => env('db_host', 'loal'),         'database' => env('db_database', 'test1'),         'username' => env('db_username', ''),         'password' => env('db_password', ''),         'charset'  => 'utf8',         'prefix'   => '',     ],     'sqlsrv2' => [         'driver'   => 'sqlsrv',         'host'     => env('db_host', 'local'),         'database' => env('db_database', 'test2'),         'username' => env('db_username', ''),         'password' => env('db_password', ''),         'charset'  => 'utf8',         'prefix'   => '',     ], 

my main db test1 , need change test2 db name in here :

 public function transactionhistory(request $request){      config::set('database.default','sqlsrv2');      dd(db::connection() ); } 

but returns null , still reading test 1. anyone?

one way change connection using db::connection() method:

$connection = db::connection('sqlsrv2'); //this create database connection using sqlsrv2 in config. 

now, can use $connection run queries, etc.

reference :


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -