Laravel Multiple db Connections

In this post, I am going to explain “How to connect multiple databases in Laravel 6”. In Laravel, we can use a multi-database connection in the application. Many times we need to use multiple databases in an application.

I will give you step by step example to implement more than one database in Laravel application using the .env file. I will show you how to add Laravel multiple DB connections also give an example of how to work with migration, model and database query for multiple database connections. So let’s follow the bellow step.

Step 1:- In the first step, you need to add a configuration variables on the .env file. let’s create as bellow:

Step 2:- Now, we need to use that variable on config file so let’s open database.php file and add new connections key as like bellow:

Step 3:- How you can use as multiple connection with migrations.

Use with model:

Use with Controller:

Leave a Comment