tal7aouy/dotenv

editing dotenv files in an easy way

v1.0.0 2022-04-19 12:45 UTC

This package is auto-updated.

Last update: 2024-05-19 17:32:35 UTC


README

Latest Version on Packagist Total Downloads run-tests

This package provides some basic tools for editing dotenv files.

Installation

You can install the package via composer:

composer require tal7aouy/dotenv

Usage

Add a section

Given we have an existing file at base_path('.env'). We can add a new section to the existing configuration file.

$dotenv = new Dotenv();

$dotenv->load(base_path('.env'));
$dotenv->heading('DB_CONNECTION');
$dotenv->set('DB_CONNECTION', 'mysql');
$dotenv->set('DB_HOST', '127.0.0.1');
$dotenv->set('DB_PORT', '3306');
$dotenv->set('DB_DATABASE', 'demo');
$dotenv->set('DB_USERNAME', 'root');
$dotenv->set('DB_PASSWORD', '');
$dotenv->getEnv('DB_DATABASE'); // demo
$dotenv->save();

This will result in the following changes.

APP_KEY=supersecret

# DB_CONNECTION
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=demo
DB_USERNAME=root
DB_PASSWORD=

Testing

> composer test

Code Style

StyleCI will apply the Laravel preset.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email oss@tjmiller.co instead of using the issue tracker.

Credits

License

Please see License File for more information.