laravel-multidomain icon indicating copy to clipboard operation
laravel-multidomain copied to clipboard

Change the database from the code

Open pixsolution opened this issue 1 year ago • 2 comments
trafficstars

Hello

With this package, how can I change the database from the code? for example from a Laravel controller? I have tried to make a request with http client: example $response = Http::get('domain2.com'); but it always return defaults database of the first .env (domain1.com) that I've in my project, it does not change me to the other domains/env that I have configured with the package How can I do?

Regards

pixsolution avatar Jan 25 '24 13:01 pixsolution

I realized that loading an env statically in bootstrap/app.php works $app->loadEnvironmentFrom('.env.domain2.com'); but I need to manage it dynamically, I have tried the following from a controller but it doesn't work

$app = app(); $app->loadEnvironmentFrom('.env.domain2.com'); $kernel = app()->make(Kernel::class); $kernel->bootstrap();

pixsolution avatar Jan 25 '24 19:01 pixsolution

hi,

what do yuo have in the supergloabl $_SERVER['SERVER_NAME']?

maybe you simply have to use 'HTTP_HOST' as pointed out in the docs,

let me know

cheers

giacomo

gecche avatar Jan 25 '24 20:01 gecche

I close the issue as you didn't reply for a while :) If there are other problems, please reopen

Thanks

Giacomo

gecche avatar Feb 21 '24 16:02 gecche