kh_dev1's avatar

dynamic database when user login

I'm a beginners on laravel I need dynamic database whenever users login example: user_a ->database_a

user_b->database_b

user_c->database_c

0 likes
15 replies
Tray2's avatar

That my friend is a really bad idea.

You only need one database, just make sure that you have a user_id in each of your tables then you will have the same end result as a database per user.

The only reason that I can see to keep them in seperate databases is if you have absurdly large data in the tables and lots of traffic but then maybe you shouldn't use a single app but rather one for each user/set of users.

1 like
Cruorzy's avatar

Seems like a really weird idea, since you are a beginner maybe explain why you think this is neccessary

1 like
kh_dev1's avatar

my boss let me do this i'm not clearly purpose of him but i think it should be can just change database connection when user login if anyone know help please i trying so long time

ahkeravi's avatar

if you want create table after login or after registration ? Or you want to create new database? @nithapple

2 likes
kh_dev1's avatar

i have database already but i just want to switch database connection and use the same modal in laravel

ahkeravi's avatar

'mysql2' => array( 'driver' => 'mysql', 'host' => 'host2', 'database' => 'database2', 'username' => 'user2', 'password' => 'pass2' 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ),

addthis this in the app/config/database.php

$users = DB::connection('mysql2')->select(...); use this in the model

@nithapple

kh_dev1's avatar

yes i know but i need dynamic when login i'm using auth

ahkeravi's avatar

currently you are using laravel auth or custom login

1 like
ahkeravi's avatar

@nithapple you can edit and asign the database in /controller/auth/LoginController.php

1 like

Please or to participate in this conversation.