Load more than one environment file

Posted 4 days ago by Raphomee


I'm using a domain for each language in laravel. mydomain.com -> en mydomain.nl -> nl mydomain.de -> de

Each language has some unique settings like Analytics ID, Mail Host etc. but most of the settings are the same (DB Connection, Redis ....).

I could use $app->loadEnvironmentFrom() to load a different .env-File for each domain but than I would have to add every setting in each file.

I would prefer to have on default .env file with all options and afterwards include another one based on the domain to override default settings (or if you cannot override them I won't add them to the default file).

I tried to use this in bootstrap/app.php

$app->afterLoadingEnvironment(function() use($app) {
    $dotenv = new Dotenv\Dotenv(__DIR__ . '/../', '.env.de');

but this results in an error

Got error 'PHP message: PHP Fatal error:  Uncaught ReflectionException: Class config does not exist in vendor/laravel/framework/src/Illuminate/Container/Container.php:794
Stack trace:
#0 vendor/laravel/framework/src/Illuminate/Container/Container.php(794): ReflectionClass->__construct('config')
#1 vendor/laravel/framework/src/Illuminate/Container/Container.php(671): Illuminate\Container\Container->build('config')
#2 vendor/laravel/framework/src/Illuminate/Container/Container.php(619): Illuminate\Container\Container->resolve('config', Array)
#3 vendor/laravel/framework/src/Illuminate/Foundation/Application.php(757): Illuminate\Container\Container->make('config', Array)
#4 vendor/laravel/framework/src/Illuminate/Container/Container.php(1233): Illuminate\Foundation\Application->make('config')
#5 vendor/laravel/framework/src/Illuminate/Log/L...'

PS: I'm using Laravel 5.8.2.

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

Reply to

Use Markdown with GitHub-flavored code blocks.