Add the package to your project :
composer require mesavolt/env
Use Mesavolt\Env::has()
to test if an environment variable exists in your app and
Mesavolt\Env::get()
to retrieve it.
Quick note: By default,
Env::get($name)
throws an exception when the variable is defined but is empty. UseEnv::getSafe($name)
to not throw an exception and get the empty value.
APP_SECRET="i can see dead people"
EMPTY_VAR=
Use it in your project :
<?php
use Mesavolt\Env;
$secret = Env::get('APP_SECRET');
$empty = Env::getSafe('EMPTY_VAR');
composer dump-autoload # make sure vendor/autoload.php exists
./vendor/bin/phpunit