Hello Artisan
In this tutorial we will discuss about laravel multiple database connections. Do you know how to connect laravel multiple database connections? If you don't know then you are right place. In this tutorial i will show you step by step that multiple db connection in laravel 7/6.
You know that sometime we need to setup multiple database connection like mysql, mongodb etc. i can say when you work with large amount of project then you will need maybe. So let's follow bellow step to learn multiple database connection in laravel 7/6.
I will add configuration variable on .env file and use it to database configuration file. You can just follow this laravel 7/6 multiple database connections tutorial, i will also teach how to work with migration, model and database query for multiple database connection.
You have to set configuration variable on .env file. do it.
.env
Now, as i created variable in .env file, we need to use that variable on config/database.php file so let's open database.php file and add new connections key as like bellow:
config/database.php
Here, i will give you simple example of how we can use as multiple connection to create migration. So to create migration just add which connection are you going to use.
Now we need to setup every model as like below before working with database.
Now we have to user controller method as like below
If you need to use query builder, then just follow and use this method.
print_r($blogs);