Awesome Open Source
Awesome Open Source


Laravel FlexEnv

Latest Version on Packagist Total Downloads Software License Build Status StyleCI

This package allows you to create, show, edit, update, and delete entries in your .env file in a Laravel project via php artisan, the command line we all know and love.



You'll have to follow a couple of simple steps to install this package.


Via composer:

$ composer require sven/flex-env:^3.0 --dev

Or add the package to your development dependencies in composer.json and run composer update sven/flex-env to download the package:

    "require-dev": {
        "sven/flex-env": "^3.0"

Registering the service provider

If you're using Laravel 5.5, you can skip this step. The service provider will have already been registered thanks to auto-discovery.

Otherwise, register Sven\FlexEnv\ServiceProvider::class manually in your AppServiceProvider's register method:

public function register()
    if ($this->app->environment() !== 'production') {


The commands in this package should now be registered. If you now run php artisan, you will see them in the list:

  • env:set
  • env:delete
  • env:get
  • env:list
  • env:example
  • env:sync

Create or edit an entry

$ php artisan env:set NEW_KEY "your key's value"

If the environment variable NEW_KEY does not exist yet, the new variable will be added to the end of the file.

Delete an entry

$ php artisan env:delete APP_KEY

This will ask for your confirmation. If you want to remove the entry without being asked, use the --force flag:

$ php artisan env:delete APP_KEY --force

Get an entry

$ php artisan env:get APP_URL


List all entries

To get a list of all entries in your .env file, use the env:list command:

$ php artisan env:list

| Key                    | Value                                               |
| APP_NAME               | Laravel                                             |
| APP_ENV                | local                                               |
| APP_KEY                | base64:b2ZJKEHJN12vpByXYmTZtGJf5bOGgPUBWlVlIQEHm2A= |
| APP_DEBUG              | true                                                |
| APP_URL                | https://localhost                                   |

You may use the --resolve-references (or -r for short) flag to tell the command to resolve any references to other environment variables in the .env file.

Let's take a look at the following example .env file:

$ php artisan env:list

| Key                | Value                      |
| PUSHER_APP_KEY     | abcdefghijklmnopqrstuvwxyz |

$ php artisan env:list --resolve-references

| Key                | Value                      |
| PUSHER_APP_KEY     | abcdefghijklmnopqrstuvwxyz |
| MIX_PUSHER_APP_KEY | abcdefghijklmnopqrstuvwxyz |

Generate .env.example file

The env:example command may be used to generate a .env.example file from your current environment file. This "example" file will only contain keys, and all the values will be stripped.

$ php artisan env:example

You can specify a name to generate a different file:

$ php artisan env:example .env-example

Synchronize the .env file with .env.example

To add keys that are present in .env.example, but are missing from .env to the .env file, use the env:sync command:

$ php artisan env:sync

This will make sure all keys from .env.example are present in the .env file. You may optionally specify the name of the "example" file to use:

$ php artisan env:sync .env-example


Inspiration for this package came from LeShadow's ArtisanExtended.


All contributions (pull requests, issues and feature requests) are welcome. Make sure to read through the first, though. See the contributors page for all contributors.


sven/flex-env is licensed under the MIT License (MIT). See the license file for more information.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
php (15,953
laravel (1,577
package (263
environment-variables (57
artisan (23

Find Open Source By Browsing 7,000 Topics Across 59 Categories