PHPackages                             cleaniquecoders/php-env-key-manager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cleaniquecoders/php-env-key-manager

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cleaniquecoders/php-env-key-manager
===================================

A framework-agnostic PHP package for easy .env file key management. Seamlessly update, add, or modify environment variables across projects with minimal configuration.

1.1.0(1y ago)6778↑200%[4 PRs](https://github.com/cleaniquecoders/php-env-key-manager/pulls)1MITPHPPHP ^8.1 | ^8.2 | ^8.3 | ^8.4CI passing

Since Nov 11Pushed 2mo agoCompare

[ Source](https://github.com/cleaniquecoders/php-env-key-manager)[ Packagist](https://packagist.org/packages/cleaniquecoders/php-env-key-manager)[ Docs](https://github.com/cleaniquecoders/php-env-key-manager)[ GitHub Sponsors](https://github.com/CleaniqueCoders)[ RSS](/packages/cleaniquecoders-php-env-key-manager/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (7)Used By (1)

PHP Env Key Manager
===================

[](#php-env-key-manager)

[![Latest Version on Packagist](https://camo.githubusercontent.com/531e197a09f72a749f3f6d7f4b208b3791f7d6dd255212161ae15d78e9062e87/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636c65616e69717565636f646572732f7068702d656e762d6b65792d6d616e616765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cleaniquecoders/php-env-key-manager) [![Tests](https://camo.githubusercontent.com/45f2969cdae3115816b7a90da393e2db5235fc7fa4d27373f650f565806a6e29/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636c65616e69717565636f646572732f7068702d656e762d6b65792d6d616e616765722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/cleaniquecoders/php-env-key-manager/actions/workflows/run-tests.yml) [![Total Downloads](https://camo.githubusercontent.com/9d440589063e54c955cd81dcdffbbc8690b7bf7b7d2aa59a8d5eb5b66bc45d31/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636c65616e69717565636f646572732f7068702d656e762d6b65792d6d616e616765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cleaniquecoders/php-env-key-manager)

A framework-agnostic PHP package for easy .env file key management. Seamlessly update, add, or modify environment variables across projects with minimal configuration.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require cleaniquecoders/php-env-key-manager
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Following are the basic usage examples for the package:

```
use CleaniqueCoders\PhpEnvKeyManager\EnvKeyManager;

// Path to your .env file
$envFilePath = __DIR__ . '/.env';
$envManager = new EnvKeyManager($envFilePath);

// Set a key
$envManager->setKey('APP_DEBUG', 'true');

// Disable a key
$envManager->disableKey('APP_DEBUG');

// Enable a key
$envManager->enableKey('APP_DEBUG');
```

---

### Framework-Specific Examples

[](#framework-specific-examples)

#### Laravel

[](#laravel)

To use `EnvKeyManager` in a Laravel application, register it as a singleton in the `AppServiceProvider` to allow easy access across your application.

Laravel Usage1. **Register as a Singleton**

    In `App\Providers\AppServiceProvider`:

    ```
    use CleaniqueCoders\PhpEnvKeyManager\EnvKeyManager;

    public function register()
    {
        $this->app->singleton(EnvKeyManager::class, function ($app) {
            return new EnvKeyManager($app->environmentFilePath());
        });
    }
    ```
2. **Usage in a Command**

    Create a Laravel Artisan command to set, disable, or enable environment keys:

    ```
