Laravel a problem with multiple databases.

Source: Internet
Author: User
These days are using laravel to develop a system. The system is connected to 2 databases. A name is blog, a name is center.

The role of the center database is as a user center. Several other systems may be connected and belong to a public database. It is mainly used for user login authentication.
The role of the blog database is to put articles, not involved in certification.

My idea is to use the center database as the user's login authentication, log in after the post switch to the blog database.

Currently my .env configuration is as follows

Db_host=localhostdb_database=blogdb_database_center=centerdb_username=rootdb_password=root

Database.php is designed in the following

    ' MySQL ' = [        ' driver '    = ' mysql ',        ' host '      = ' env ' (' db_host ', ' localhost '),        ' database '  = = env (' db_database ', ' Forge '),        ' username '  = env (' db_username ', ' Forge '),        ' password '  + env (' Db_password ', '),        ' charset '   = ' utf8 ',        ' collation ' = ' utf8_unicode_ci ',        ' Prefix ' = = '    ,        ' strict ' and    false,    ],    ' mysql_center ' = '        = ' driver '    = > ' mysql ',        ' host '      = env (' db_host ', ' localhost '),        ' database '  = env (' Db_database_ CENTER ', ' Forge '),        ' username '  = env (' db_username ', ' Forge '),        ' password '  = env (' Db_ PASSWORD ', '),        ' charset ' = '   utf8 ',        ' collation ' = ' utf8_unicode_ci ',        ' prefix '    = > ',        ' strict '    = False,    ],

The model I built myself User.php can switch databases in this way.

Class User extends Model implements Authenticatablecontract, canresetpasswordcontract{    protected $connection = ' Mysql_center ';

But the system comes with the example of how to switch the database controller?

app\http\controllers\auth\authcontroller.phpapp\http\controllers\auth\passwordcontroller.php

I hope you can help answer, thank you!

Reply content:

These days are using laravel to develop a system. The system is connected to 2 databases. A name is blog, a name is center.
The role of the center database is as a user center. Several other systems may be connected and belong to a public database. It is mainly used for user login authentication.
The role of the blog database is to put articles, not involved in certification.

My idea is to use the center database as the user's login authentication, log in after the post switch to the blog database.

Currently my .env configuration is as follows

Db_host=localhostdb_database=blogdb_database_center=centerdb_username=rootdb_password=root

Database.php is designed in the following

    ' MySQL ' = [        ' driver '    = ' mysql ',        ' host '      = ' env ' (' db_host ', ' localhost '),        ' database '  = = env (' db_database ', ' Forge '),        ' username '  = env (' db_username ', ' Forge '),        ' password '  + env (' Db_password ', '),        ' charset '   = ' utf8 ',        ' collation ' = ' utf8_unicode_ci ',        ' Prefix ' = = '    ,        ' strict ' and    false,    ],    ' mysql_center ' = '        = ' driver '    = > ' mysql ',        ' host '      = env (' db_host ', ' localhost '),        ' database '  = env (' Db_database_ CENTER ', ' Forge '),        ' username '  = env (' db_username ', ' Forge '),        ' password '  = env (' Db_ PASSWORD ', '),        ' charset ' = '   utf8 ',        ' collation ' = ' utf8_unicode_ci ',        ' prefix '    = > ',        ' strict '    = False,    ],

The model I built myself User.php can switch databases in this way.

Class User extends Model implements Authenticatablecontract, canresetpasswordcontract{    protected $connection = ' Mysql_center ';

But the system comes with the example of how to switch the database controller?

app\http\controllers\auth\authcontroller.phpapp\http\controllers\auth\passwordcontroller.php

I hope you can help answer, thank you!

Authcontroller default is to use "app\user" eloquent model, similarly, you specify a database in the App\user.

Add the two sections of login registration and password retrieval implemented in the Auth case that Laravel 5 comes with.
The method that can be used for registering the login section ylem .

For password retrieval, it needs to be /config/auth.php set up inside.
For example:

' Table ' = ' mydatabases.password_resets ',
' Host '      = env (' db_host ', ' localhost '),    ' database '  = env (' Db_database_center ', ' Forge '),    ' Username '  = env (' db_username ', ' Forge '),    ' password '  = env (' Db_password ', '),    ' CharSet '   = ' UTF8 ',    ' collation ' = ' utf8_unicode_ci ',            ================== wrong ... Get rid of ENV,  env (' db_database_center ', ' Forge ') leave only ' forge ',    env (' Db_password ', '), just leave '               * * I solved this problem, As a novice, I spent a cumulative time of   two days */
  • Related Article

    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.