PHPackages                             thegr8dev/dotenv-editor - 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. thegr8dev/dotenv-editor

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

thegr8dev/dotenv-editor
=======================

The .env file editor tool for Laravel 5.8+

1.3.0(4y ago)022MITPHP

Since May 15Pushed 4y agoCompare

[ Source](https://github.com/thegr8dev/Laravel-Dotenv-Editor)[ Packagist](https://packagist.org/packages/thegr8dev/dotenv-editor)[ RSS](/packages/thegr8dev-dotenv-editor/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (16)Used By (0)

Laravel Dotenv Editor
=====================

[](#laravel-dotenv-editor)

[![laravel-dotenv-editor](https://cloud.githubusercontent.com/assets/9862115/25982836/029612b2-370a-11e7-82c5-d9146dc914a1.png)](https://cloud.githubusercontent.com/assets/9862115/25982836/029612b2-370a-11e7-82c5-d9146dc914a1.png)

[![Latest Stable Version](https://camo.githubusercontent.com/a557d182ebab1601552abc23c5c2befbb0fc8ea2ebde3173308a7f80faaf7916/68747470733a2f2f706f7365722e707567782e6f72672f6a61636b6965646f2f646f74656e762d656469746f722f762f737461626c65)](https://packagist.org/packages/jackiedo/dotenv-editor)[![Total Downloads](https://camo.githubusercontent.com/4824d6be3c6b5e1a576a505952a3310168534f2e7c3ea8d9297f8ecb6bc88a83/68747470733a2f2f706f7365722e707567782e6f72672f6a61636b6965646f2f646f74656e762d656469746f722f646f776e6c6f616473)](https://packagist.org/packages/jackiedo/dotenv-editor)[![Latest Unstable Version](https://camo.githubusercontent.com/18c67cc473fb232493af158b1e4d89963bf4d148d764db4960c825c89b3177e0/68747470733a2f2f706f7365722e707567782e6f72672f6a61636b6965646f2f646f74656e762d656469746f722f762f756e737461626c65)](https://packagist.org/packages/jackiedo/dotenv-editor)[![License](https://camo.githubusercontent.com/9b443b26b04c27543b8bff45406c6f63081b187c95947fa631d041afdda0c244/68747470733a2f2f706f7365722e707567782e6f72672f6a61636b6965646f2f646f74656e762d656469746f722f6c6963656e7365)](https://packagist.org/packages/jackiedo/dotenv-editor)

Laravel Dotenv Editor is the .env file editor (or files with same structure and syntax) for Laravel 5.8+. Now you can easily edit .env files with the following features:

- Read raw content of file.
- Read lines of file content.
- Read setters (key-value-pair) of file content.
- Determine one key name of existing setter.
- Append empty lines to file.
- Append comment lines to file.
- Append new or update exists setter lines to file.
- Delete existing setter line in file.
- Backup and restore file.
- Manage backup files.

Versions and compatibility
==========================

[](#versions-and-compatibility)

Laravel Dotenv Editor is compatible with Laravel 5+ and above. Since the release of `1.2.0` onwards, this package only supports Laravel 5.8 and later. Previous versions of Laravel will no longer be supported.

Note for the release `1.2.0` and later
======================================

[](#note-for-the-release-120-and-later)

Starting with the release `1.2.0`, the .gitignore file in the folder containing the backup file will no longer be created automatically. Developers will have to create this file manually if deemed necessary.

Documentation
=============

[](#documentation)

Look at one of the following topics to learn more about Laravel Dotenv Editor:

- [Installation](#installation)
- [Configuration](#configuration)
    - [Auto backup mode](#auto-backup-mode)
    - [Backup location](#backup-location)
    - [Always create backup folder](#always-create-backup-folder)
- [Usage](#usage)
    - [Working with facade](#working-with-facade)
    - [Using dependency injection](#using-dependency-injection)
    - [Loading file for working](#loading-file-for-working)
    - [Reading file content](#reading-file-content)
    - [Writing content into file](#writing-content-into-file)
    - [Backing up and restoring file](#backing-up-and-restoring-file)
    - [Method chaining](#method-chaining)
    - [Working with Artisan CLI](#working-with-artisan-cli)
    - [Exceptions](#exceptions)

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

[](#installation)

You can install this package through [Composer](https://getcomposer.org) with the following steps:

#### Step 1 - Require package

[](#step-1---require-package)

At the root of your application directory, run the following command (in any terminal client):

```
$ composer require jackiedo/dotenv-editor
```

**Note:** Since Laravel 5.5, [service providers and aliases are automatically registered](https://laravel.com/docs/5.5/packages#package-discovery), so you can safely skip the following two steps:

#### Step 2 - Register service provider

[](#step-2---register-service-provider)

Open `config/app.php`, and add a new line to the providers section:

```
Jackiedo\DotenvEditor\DotenvEditorServiceProvider::class,
```

#### Step 3 - Register facade

[](#step-3---register-facade)

Add the following line to the aliases section in file `config/app.php`:

```
'DotenvEditor' => Jackiedo\DotenvEditor\Facades\DotenvEditor::class,
```

Configuration
-------------

[](#configuration)

To start using the package, you should publish the configuration file so that you can configure the package as needed. To do that, run the following command (in any terminal client) at the root of your application:

```
$ php artisan vendor:publish --provider="Jackiedo\DotenvEditor\DotenvEditorServiceProvider" --tag="config"
```

This will create a `config/dotenv-editor.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases. Currently there are the following settings:

#### Auto backup mode

[](#auto-backup-mode)

The `autoBackup` setting allows your original file to be backed up automatically before saving. Set it to `true` to agree.

#### Backup location

[](#backup-location)

The `backupPath` setting is used to specify where your file is backed up. This value is a sub path (sub-folder) from the root folder of the project application.

#### Always create backup folder

[](#always-create-backup-folder)

The `alwaysCreateBackupFolder` setting is used to request that the backup folder always be created, whether or not the backup is performed.

Usage
-----

[](#usage)

### Working with facade

[](#working-with-facade)

Laravel Dotenv Editor has a facade with the name `Jackiedo\DotenvEditor\Facades\DotenvEditor`. You can perform all operations through this facade.

**Example:**

```
