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
Asked
Active
Viewed 47 times
0
-
Please search about `Micro service` concept – Shibon Apr 24 '19 at 06:14
-
Possible duplicate of [How to use multiple databases in Laravel](https://stackoverflow.com/questions/31847054/how-to-use-multiple-databases-in-laravel) – Keivan Esbati Apr 24 '19 at 06:32
1 Answers
0
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);

Johnwel Pol
- 77
- 3