check .env variables Hello
I have lumen application
in bootstrap/app.php I have code which loads env variables from .env file
via this code
$bootstrap = new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
dirname(__DIR__)
);
$bootstrap->bootstrap();`
what is good way to check that .env file contains all required variables ?
Do you mean programmatically??? What determines a required environment variable?
@tykus programmatically
required means that this is necessary in order to run application
for example I provide a list of mandatory vars and application fails if one of them is not there
Solution I found
try {
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->required(
[
'APP_ENV',
'DB_HOST',
'DB_PORT',
'DB_NAME',
'DB_USER',
'DB_PASS'
]
);
} catch (Exception $e) {
die("Check bootstrap configuration: {$e->getMessage()}");
}
If var from list does not exist then it throws an excetion and you can handle it
Please sign in or create an account to participate in this conversation.