gecche / laravel-multidomain

A Laravel extension for using a laravel application on a multi domain setting
MIT License
851 stars 107 forks source link

Change the database from the code #108

Closed pixsolution closed 9 months ago

pixsolution commented 10 months ago

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 commented 10 months ago

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();

gecche commented 10 months ago

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 commented 9 months ago

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

Thanks

Giacomo