简体   繁体   中英

Different .env file for different URL in Laravel

I have a Laravel application running at www.myapp.com with its own logos and all, the logo file location is defined in a .env file.

Now I want to have a white-label of www.myapp.com application on www.whitelabel.com with its own logo.

I need to have two different .env files that need to be loaded at runtime eg - for www.myapp.com in URL it should use .myapp.env file - and for www.whitelabel.com it should use .whitelabel.env file.

Is this possible in Laravel 5.1, if yes how?

I solved it using Dotenv::load function in Laravel 5.1. Add following code in bootstrap/app.php before return $app;

$environmentPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
$environmentFile = null;
switch (getenv('HTTP_HOST')) {
    case 'whitelabel.com':
        $environmentFile = '.whitelabel.env';
        break;
}
if (!empty($environmentFile) && file_exists($environmentPath . $environmentFile)) {
    Dotenv::load($environmentPath , $environmentFile);
}

Hope it help someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM