I need to use another db connection just for 1 user.
First of all I created another connection in the config/database.php file:
'mysqltest' => [
'driver' => 'mysql',
//...
],
It works. I tried it with something like this Model::on('mysqltest')->all()
.
Now I would like to change connection everywhere in the project, so I thought to change it after user login.
I'm trying this without success:
protected function authenticated(Request $request, $user)
{
//
if ($user->user_id == 1) {
//DB::purge('mysqltest');
//DB::reconnect('mysqltest');
DB::setDefaultConnection('mysqltest');
}
}
Create middleware for example
php artisan make:middleware SelectDB
Add middleware in App\Http\Kernel