Answer the question
In order to leave comments, you need to log in
How to set up work with two bases on Laravel?
Hello!
The challenge is to divide all application users into two groups, say "Russians" and "Americans", with two separate databases. Depending on which group the user belongs to, output data from the corresponding database. The group itself is defined in the table users
for each user separately.
In the file config/database.php
, I added a new connection for the second database.
The output of all data for the user is processed through the controllers. I tried to use group membership check and return data via DB::connection,
but inside the controller it doesn't work. DB::
defined as a controller that is not initialized.
Is there a way at the time of user authorization to determine his group and, depending on it, immediately establish the necessary connection to the required database on a permanent basis for this user? I have read that this seems to be possible via IoC, but I have no idea how this is done.
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
...inside the controller it doesn't work. DB:: is defined as a controller that is not initialized.
\DB::connection(...)
. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question