- PHP >= 7.3
composer require codezero/dotenv-updater
Create an instance of the DotEnvUpdater
and pass it the path to the .env
file:
$updater = new \CodeZero\DotEnvUpdater\DotEnvUpdater('/path/to/.env');
Add any new, or overwrite any existing key/value pairs:
$updater->set('MY_ENV_KEY', 'Some Value'); // Strings
$updater->set('MY_ENV_KEY', 25); // Integers
$updater->set('MY_ENV_KEY', true); // Booleans
$updater->set('MY_ENV_KEY', null); // NULL values
$updater->set('MY_ENV_KEY', ''); // Empty values
Retrieve the value of a key:
$value = $updater->get('MY_ENV_KEY');
composer test
If you discover any security related issues, please e-mail me instead of using the issue tracker.
A complete list of all notable changes to this package can be found on the releases page.
The MIT License (MIT). Please see License File for more information.