amdadulhaq/env-editor-laravel

ENV Editor for laravel

Fund package maintenance!
amdad121

Installs: 273

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/amdadulhaq/env-editor-laravel

v2.0.0 2026-01-02 18:34 UTC

This package is auto-updated.

Last update: 2026-01-02 18:35:08 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Simple and powerful ENV file editor for your Laravel application.

Installation

You can install the package via composer:

composer require amdadulhaq/env-editor-laravel

Usage

Basic Methods

use AmdadulHaq\EnvEditor\EnvEditor;

// Set a new key or update an existing one
EnvEditor::set('APP_NAME', 'MyApp');

// Update an existing key (throws exception if key doesn't exist)
EnvEditor::update('APP_NAME', 'MyApp');

// Set or update (smart - checks if key exists)
EnvEditor::setOrUpdate('APP_NAME', 'MyApp');

// Remove a key
EnvEditor::remove('APP_NAME');

Reading Values

// Get a single value
$appName = EnvEditor::get('APP_NAME');
$appName = EnvEditor::get('NON_EXISTENT_KEY', 'default_value'); // with default

// Get all values as an array
$allEnv = EnvEditor::getAll();

// Check if a key exists
$hasKey = EnvEditor::has('APP_NAME');

Backup and Restore

// Create a backup (auto-generates timestamp-based filename)
$backupPath = EnvEditor::backup();

// Create a backup with custom name
$backupPath = EnvEditor::backup('backup-before-deployment.env');

// List all available backups
$backups = EnvEditor::listBackups();

// Restore from a backup
EnvEditor::restore('backup-before-deployment.env');

Using with Dependency Injection

use AmdadulHaq\EnvEditor\EnvEditor;

class SomeService
{
    public function __construct(
        protected EnvEditor $envEditor
    ) {}

    public function updateSettings()
    {
        $this->envEditor->set('SOME_KEY', 'value');
        $value = $this->envEditor->get('SOME_KEY');
    }
}

Custom ENV File Path

If you need to work with a different .env file:

$editor = new EnvEditor('/path/to/custom/.env');
$editor->set('KEY', 'value');

Features

  • ✅ Read, write, and update .env file values
  • ✅ Check if keys exist
  • ✅ Get all environment variables as an array
  • ✅ Backup and restore .env files
  • ✅ Handle values with spaces, quotes, and special characters
  • ✅ Dependency injection support
  • ✅ Custom .env file path support
  • ✅ Comprehensive error handling
  • ✅ Full test coverage with Pest

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.