Few day back while developing an application I come up to a point where I need to connect to the different database dynamically. I google around and I found few good solution in multiple websites; So I thought to stitch them into a single piece.
Before proceeding we first have to edit our
database.php which is located in
/config/database.php for Lavael 4.2 it is in
Now that we have set the DB connections it’s time to use it
Defining in Model
If have Model which uses a different database then we can define it at the model level like this:
In Eloquent Query
In DB Query
Let me know through the comment if I missed out any point. Cheers!