Posted inTechnology / Laravel / Mysql / Mysqli / php / Programming

Multiple Database Connections using Laravel

Multiple Database Connections using Laravel

In this Post We Will Explain About is Multiple Database Connections using Laravel With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to connect multiple database in laravel Example

In this post we will show you Best way to implement How to connect multiple database in laravel 5.5, hear for laravel use multiple database with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Step 1 : Install Laravel

In some multiple protect we need to use database connect to multiple databases for same web-application. Lets Display how to use step by step multiple database using laravel 5.5 First of allInstall We laravel Web-application as well as simple connect with primary main database

Step 2 : MAke a database in Mysql

Make simple second database in We use own phpmyadmin

Step 3 : config/database.php

Generally simple provide We database connection Information in We config/database.php

Like as a …

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'), //host
            'port' => env('DB_PORT', '3306'),//port
            'database' => env('DB_DATABASE', 'forge'),//dbname
            'username' => env('DB_USERNAME', 'forge'),//username
            'password' => env('DB_PASSWORD', ''),//password
            'unix_socket' => env('DB_SOCKET', ''),//socket
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,

        'mysql2' => [
            'driver' => 'mysql',
            'host' => 'localhost', //hostname
            'port' => '3306',		//port
            'database' => 'multiple',//databasename
            'username' => 'root', //username
            'password' => 'root', //password
            'unix_socket' => '',
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,

Step 4 :

Use We database connection in Schema to Make table for We new tables for new database

//laravel simple create migrate up methods
public function up()
        Schema::connection('mysql2')->create('roles', function (Blueprint $table) {

     * Reverse simple laravel the migrations.
     *data type
     * @return void
	 //laravel simple create migrate Down methods
    public function down()

Step 5 : run Project

Run We need to browser laravel migration to Make table

php artisan migrate --database="YourDatabaseConnName"

Step 6 : database Connection

All the Product We model with connection

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details......
Angularjs Example


I hope you have Got What is How to connect multiple database in laravel 5.5 And how it works.I would Like to have FeedBack From My Blog( readers.Your Valuable FeedBack,Any Question,or any Comments about This Article( Are Most Always Welcome.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype