Laravel 7/6 Multiple Database Connection Tutorial (ok)
https://www.itsolutionstuff.com/post/laravel-6-multiple-database-connection-tutorialexample.html
C:\xampp\htdocs\reset\.env
APP_NAME=Test
APP_ENV=local
APP_KEY=base64:Oki7sndHBwYxkCBwH0gtS44oKrtsL+xjN07/KKWtA+c=
APP_DEBUG=true
APP_URL=http://localhost/reset
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=reset
DB_USERNAME=root
DB_PASSWORD=
DB_CONNECTION_SECOND=mysql
DB_HOST_SECOND=127.0.0.1
DB_PORT_SECOND=3306
DB_DATABASE_SECOND=reset2
DB_USERNAME_SECOND=root
DB_PASSWORD_SECOND=
BROADCAST_DRIVER=redis
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
LARAVEL_ECHO_PORT=6001
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=phamngoctuong1805@gmail.com
MAIL_PASSWORD=lufcvcbdnbjcrvta
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=phamngoctuong1805@gmail.com
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"C:\xampp\htdocs\reset\config\database.php
C:\xampp\htdocs\reset\routes\web.php
C:\xampp\htdocs\reset\resources\views\products.blade.php
C:\xampp\htdocs\reset\app\Http\Controllers\ProductController.php
C:\xampp\htdocs\reset\database\migrations\2022_05_20_161330_create_products_table.php

Laravel 7/6 Multiple Database Connection Tutorial
By Hardik Savani December 4, 2019 Category : LaravelPlayUnmuteLoaded: 1.17%Fullscreen
Today, i would like to show you how to use multiple db connection in laravel 7/6 application. we will learn to use multi database connection laravel 7/6. you will find out way of implementing laravel 7/6 multiple database connection example.
I will give you step by step implementation of how to use laravel 6 multiple database connections using .env file. we will add configuration variable on .env file and use it to database configuration file. You can just follow me, i will also learn how to work with migration, model and database query for multiple database connection.
As we know sometime we need to use 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.

Set ENV Variable:
Here, you need to set configuration variable on .env file. let's create as bellow:
.env
Use ENV Variable:
Now, as we created variable in env file, we need to use that variable on config file so let's open database.php file and add new connections key as like bellow:
config/database.php
Use Database Multiple Connection:
Here, i will give you simple example of how you can use as multiple connection:
Use with migration
Use with model
Use with Controller
Use with Query Builder
Read Also: Laravel 8/7 Notification Tutorial | Create Notification with Laravel 8/7
Last updated
Was this helpful?


