In the past few days, Laravel has been used to develop a system. This system connects two databases. A name is blog and a name is center. The center database serves as the user center. Several other systems may be connected to the public database. It is mainly used for user login authentication. Blog data... a system is being developed using Laravel these days. This system connects two databases. A name is blog and a name is center.
The center database serves as the user center. Several other systems may be connected to the public database. It is mainly used for user login authentication.
The function of the blog database is to publish an article, which does not involve authentication.
My idea is to use the center database as the user's login authentication. After logging on, I will send an article to switch to the blog database.
Currently, my.envThe configuration is as follows:
DB_HOST=localhostDB_DATABASE=blogDB_DATABASE_CENTER=centerDB_USERNAME=rootDB_PASSWORD=root
The design in database. php is as follows:
'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' => 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, ],
My own modelUser.phpYou can switch the database in the following way.
class User extends Model implements AuthenticatableContract, CanResetPasswordContract{ protected $connection = 'mysql_center';
But how does the Controller switch the database in the example provided by the system?
app\Http\Controllers\Auth\AuthController.phpapp\Http\Controllers\Auth\PasswordController.php
I hope you can help me solve this problem. Thank you!
Reply content:
In the past few days, Laravel has been used to develop a system. This system connects two databases. A name is blog and a name is center.
The center database serves as the user center. Several other systems may be connected to the public database. It is mainly used for user login authentication.
The function of the blog database is to publish an article, which does not involve authentication.
My idea is to use the center database as the user's login authentication. After logging on, I will send an article to switch to the blog database.
Currently, my.envThe configuration is as follows:
DB_HOST=localhostDB_DATABASE=blogDB_DATABASE_CENTER=centerDB_USERNAME=rootDB_PASSWORD=root
The design in database. php is as follows:
'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' => 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, ],
My own modelUser.phpYou can switch the database in the following way.
class User extends Model implements AuthenticatableContract, CanResetPasswordContract{ protected $connection = 'mysql_center';
But how does the Controller switch the database in the example provided by the system?
app\Http\Controllers\Auth\AuthController.phpapp\Http\Controllers\Auth\PasswordController.php
I hope you can help me solve this problem. Thank you!
See document: http://laravel.com/docs/master/authentication
AuthController uses the "App \ User" Eloquent model by default. Similarly, you can specify a database in App \ User.
Add the login registration and password retrieval sections in the Auth case provided by laravel 5.
You can useylem.
For password retrieval/config/auth.php.
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', 'colation' => 'utf8 _ unicode_ci ', ========================== incorrect writing ...... Remove env, env ('db _ DATABASE_CENTER ', 'forge'), leaving only 'forge', env ('db _ password ',''), I only left ''/* behind to solve this problem. As a newbie, I spent a total of two days */