Multiple DB Connections in Laravel 5

Multiple DB Connections in Laravel 5

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 app/config/database.php.

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!

Share this Post:

About Rana Ghosh

I'm a PHP, MySQL, jQuery expert, and designing specialist. My elating approach of seeing web world with a different sight leaves others amazed. My skills include codeigniter, Laravel. I enjoy taking challenges. I love to play FIFA Online 3.  

Related Posts:

One thought on “Multiple DB Connections in Laravel 5

Leave a Comment

Your email address will not be published. Required fields are marked *


*