简体   繁体   中英

How can i use multiple database in laravel like one group one databse?

I want to know about laravel multiple database. is it possible to use a default database which use only user login and after login separate group by group and every group use independent database. such as 'db' is the default database it's only for the all user login. Example: Now 'John' is login using default database 'db'. John is the member of group1 after login john use 'db1' where stored John's all type of data. Other side Now 'Alex' login using default database 'db'. Alex is the member of group2 after login Alex use 'db2' where stored Alex's all type of data. After login default db connection no need so i want to replace 'bd' to 'db1' or 'db' to 'db2'. Please provide code for laravel

create an instance of database connection like this one: 'connections' => [

    'newDBconnection' => [
        'driver' => 'sqlite',
        'database' => env('DB_DATABASE', database_path('database.sqlite')),
        'prefix' => '',
        'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
    ]

] on config/database.php and use like this :

$sql = "INSERT IGNORE INTO sample_table (column, column1,column2, column3 ) VALUES ('{$value}','{$value1}','{$value2}',{$value3});"; DB::connection('newDBconnection')->select($sql);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM