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'], | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
MacWorks commentedJan 29, 2016
I had some difficulty with calling this command. It turned out I needed to adjust the signature
protected $signature = 'encrypt-env {value*}';