Laravel multiple db connections

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

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

Step 1:- In first step, you need to add configuration variable on .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:


Add a Comment

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