Connect multiple databases using the eloquent model of the LARAVEL framework

Source: Internet
Author: User

1. Configure the. env file

db_host_trailer=127.0.0.1
db_port_trailer=3306
Db_database_trailer=htms_trailer
Db_username_trailer=root
Db_password_trailer=

db_host_freight=127.0.0.1
db_port_freight=3306
Db_database_freight=hangli_saas
Db_username_freight=root
db_password_freight=

2, Configuration config/database.php

' Mysql_freight ' = [' driver ' = ' mysql ', ' host ' = ' env ' (' db_host_freight ', ' Localho St '), ' database ' = env (' db_database_freight ', ' Forge '), ' username ' = env (' Db_username_frei            GHT ', ' Forge '), ' password ' = env (' db_password_freight ', '), ' charset ' = ' utf8 ', ' Collation ' = ' utf8_unicode_ci ', ' prefix ' = ', ' strict ' and ' = False, ' E      Ngine ' = null,], ' mysql_trailer ' = [' driver ' = ' mysql ', ' host '            = env (' db_host_trailer ', ' localhost '), ' database ' = env (' Db_database_trailer ', ' Forge '),            ' Username ' = env (' Db_username_trailer ', ' Forge '), ' password ' = env (' Db_password_trailer ', '),            ' CharSet ' = ' utf8 ', ' collation ' and ' utf8_unicode_ci ', ' prefix ' = ', ' ' Strict ' = False, ' engine ' = null,], 

3. Modify Model

$connection ' Mysql_freight ';

Connect multiple databases using the eloquent model of the LARAVEL framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.