generateRandomKey(); if ($this->option('show')) { return $this->line(''.$key.''); } // Next, we will replace the application key in the environment file so it is // automatically setup for this developer. This key gets generated using a // secure random byte generator and is later base64 encoded for storage. $this->setKeyInEnvironmentFile($key); $this->laravel['config']['app.key'] = $key; $this->info("Application key [$key] set successfully."); } /** * Set the application key in the environment file. * * @param string $key * @return void */ protected function setKeyInEnvironmentFile($key) { // Unlike Illuminate\Foundation\Console\KeyGenerateCommand, // I add some spaces to the replace pattern. file_put_contents($this->laravel->environmentFilePath(), str_replace( 'APP_KEY = '.$this->laravel['config']['app.key'], 'APP_KEY = '.$key, file_get_contents($this->laravel->environmentFilePath()) )); } /** * Generate a random key for the application. * * @return string */ protected function generateRandomKey() { return 'base64:'.base64_encode(random_bytes( $this->laravel['config']['app.cipher'] == 'AES-128-CBC' ? 16 : 32 )); } }