Crazylife
5 months ago

How to set persistent database connection for different user from different country login?

Posted 5 months ago by Crazylife

I have tried to use middleware, e.g.

 $country  = $request->route()->parameter('country');

        DB::disconnect();
        Config::set('database.default','test_'.$country);
        DB::reconnect();

//my route
Route::group([
    'prefix' => '{country}',
    'middleware' => 'locale'
], function() {
.....
  Route::group(['prefix' => 'user'], function () {
Auth::route();
......
    });
    });

It works for register and login, but failed for others like view user account...etc.

May i know what's wrong with this?

I am trying to set up 1 database for 1 country. Should i just set it in app service provider using request::segment and config set my database?

Please sign in or create an account to participate in this conversation.