zoukankan      html  css  js  c++  java
  • lumen 5.6 设置APP_KEY为32位长的随机字符串

     

    在 AppConsoleCommands下 添加以下内容的KeyGenerateCommand.php文件

    <?php
    
    namespace AppConsoleCommands;
    
    use IlluminateConsoleCommand;
    
    class KeyGenerateCommand extends Command
    {
    	/**
    	 * The name and signature of the console command.
    	 *
    	 * @var string
    	 */
    	protected $signature = 'key:generate';
    
    	/**
    	 * The console command description.
    	 *
    	 * @var string
    	 */
    	protected $description = 'Set the application key';
    
    	/**
    	 * Execute the console command.
    	 *
    	 * @return void
    	 */
    	public function handle()
    	{
    		$key = $this->generateRandomKey();
    
    		file_put_contents(base_path('.env'), preg_replace(
    			'/^APP_KEY=[w]*/m',
    			'APP_KEY='.$key,
    			file_get_contents(base_path('.env'))
    		));
    
    		$this->info("Application key [$key] set successfully.");
    	}
    
    	/**
    	 * Generate a random key for the application.
    	 *
    	 * @return string
    	 */
    	protected function generateRandomKey()
    	{
    		return str_random(32);
    	}
    
    }
    

    将指令注入
    修改AppConsole 下的Kernel.php 文件

    protected $commands = [
    	    'AppConsoleCommandsKeyGenerateCommand',
        ];
    

    复制.env.example 为.env文件 

    现在可以使用 php artisan key:generate 指令 修改 .env中的APP_KEY 的值

  • 相关阅读:
    webpack配置
    gulp-babel 取消严格模式方法
    时间线
    tojson
    [[],[],[]]这样的数据转化成[{},{},{}]
    BUGFREE的安装
    Linux 打包压缩与搜索命令
    Linux 文件目录管理命令
    Linux 文本文件编辑命令
    Linux 工作目录切换命令
  • 原文地址:https://www.cnblogs.com/brady-wang/p/10639211.html
Copyright © 2011-2022 走看看