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 ' =False,],' Mysql_center ' = [' Driver ' = ' MySQL ', ' host ' = env ( ' db_host ' , ' database ' = env ( ' Db_database_center ', ' Forge '), ' Db_username ', ' Forge '), ' password ' + env ( ' Db_password ', ' charset ' + ' UTF8 ', ' collation ' = Span class= "hljs-string" > ' 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!
- June 23, 2015 question
- Comments
- Invitation to answer
- Edit
- More
4 answers
0
has been adopted
Look at the documentation: Http://laravel.com/docs/master/authentication
Authcontroller default is to use "app\user" eloquent model, similarly, you specify a database in the App\user.
- June 23, 2015 answer
- 1 reviews
- Edit
Ylem22 Prestige
0
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‘,
- June 24, 2015 answer
- Comments
- Edit
Me110117 Prestige
0
' Host ' = env (' Db_host ',' localhost '),' Database ' = env ( ' Db_database_center ', ' Forge '), ' Db_username ', ' Forge '), ' password ' + env ( ' Db_password ', ' charset ' + ' UTF8 ', ' collation ' = Span class= "hljs-string" > ' utf8_unicode_ci ', ================== spelling error ... Remove env, env ( ' Db_database_center ', ' Forge ') leaving only ' Forge ', env ( ' Db_password ', " /* I have solved this problem, as a novice, I spent the cumulative time two days */
- March 21 Response • March 21 Update
- Comments
- Edit
Clarkwayne1 Prestige
0
It's written in the controller.
$results = DB::connection(‘mysql‘)->select(‘...‘); $results = DB::connection(‘mysql_center‘)->select(‘...‘);
Laravel a problem with multiple databases.