Skip to content

Instantly share code, notes, and snippets.

@ukautz
Last active July 19, 2016 23:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukautz/5f9b7fca62bfaead886b to your computer and use it in GitHub Desktop.
Save ukautz/5f9b7fca62bfaead886b to your computer and use it in GitHub Desktop.
Laravel command to encrypt environment variable values for safe storage
<?php
// app/Console/Commands/EncryptEnvCommand.php
namespace Ictus\Hub\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Encryption\Encrypter;
use Symfony\Component\Console\Input\InputArgument;
class EncryptEnvCommand extends Command
{
protected $name = 'encrypt-env';
protected $description = 'Encrypt environment variable value so it can be safely stored';
public function handle()
{
$crypt = new Encrypter(config("env.key"));
foreach ($this->argument('value') as $value) {
$this->output->writeln("ENC:" . $crypt->encrypt($value));
}
}
protected function getArguments()
{
return [
['value', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Value of the environment variable'],
];
}
}
@MacWorks
Copy link

I had some difficulty with calling this command. It turned out I needed to adjust the signature

protected $signature = 'encrypt-env {value*}';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment