Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

MacWorks commented Jan 29, 2016

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
You can’t perform that action at this time.