Last active
July 19, 2016 23:35
-
-
Save ukautz/5f9b7fca62bfaead886b to your computer and use it in GitHub Desktop.
Laravel command to encrypt environment variable values for safe storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
I had some difficulty with calling this command. It turned out I needed to adjust the signature
protected $signature = 'encrypt-env {value*}';