84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
How to change the database in Laravel's auth.php (config/auth.php)? I'm working with multiple databases and want to store users in another database.
Set the connection in the User.php model or an Auth-related model.
First, you should define the connection in config/database.php:
'connections' => [ 'global' => [ 'driver' => 'mysql', 'host' => env('first_db_name', '127.0.0.1'), ... ], 'tennant' => [ 'driver' => 'sqlite', 'host' => env('sec_db_name', '127.0.0.1'), ], ]
Then add them in auth.php:
auth.php
'guards' => [ [...] 'global' => [ 'driver' => 'session', 'provider' => 'globals', ], 'tennant' => [ 'driver' => 'session', 'provider' => 'tennants', ], ], [...] 'providers' => [ [...] 'globals' => [ 'driver' => 'eloquent', 'model' => App\UserGlobal::class, ], 'tennants' => [ 'driver' => 'eloquent', 'model' => App\UserTennant::class, ], ],
Define protected $connection = 'connection name' in each verifiable model, and finally use in the model:
$connection = 'connection name'
protected $connection = 'connectionname';
Set the connection in the User.php model or an Auth-related model.
First, you should define the connection in config/database.php:
Then add them in
auth.php
:Define protected
$connection = 'connection name'
in each verifiable model, and finally use in the model: