svenluijten / Flex Env
Projects that are alternatives of or similar to Flex Env
Laravel FlexEnv
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.
Index
Installation
You'll have to follow a couple of simple steps to install this package.
Downloading
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') {
$this->app->register(\Sven\FlexEnv\ServiceProvider::class);
}
}
Usage
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
http://localhost
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:
PUSHER_APP_KEY=abcdefghijklmnopqrstuvwxyz
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
$ php artisan env:list
+--------------------+----------------------------+
| Key | Value |
+--------------------+----------------------------+
| PUSHER_APP_KEY | abcdefghijklmnopqrstuvwxyz |
| MIX_PUSHER_APP_KEY | "${PUSHER_APP_KEY}" |
+--------------------+----------------------------+
$ php artisan env:list --resolve-references
+--------------------+----------------------------+
| Key | Value |
+--------------------+----------------------------+
| PUSHER_APP_KEY | abcdefghijklmnopqrstuvwxyz |
| MIX_PUSHER_APP_KEY | abcdefghijklmnopqrstuvwxyz |
+--------------------+----------------------------+
.env.example
file
Generate 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
.env
file with .env.example
Synchronize the 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
Inspiration for this package came from LeShadow's ArtisanExtended.
Contributing
All contributions (pull requests, issues and feature requests) are welcome. Make sure to read through the CONTRIBUTING.md first, though. See the contributors page for all contributors.
License
sven/flex-env
is licensed under the MIT License (MIT). See the license file
for more information.