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 */