public function setKey()
    {
        if(trim(env('APP_KEY')) != '') {
            return true;
        }
        $appKey='';
        for($i=0;$i<32;$i++) {
            $appKey.=chr(rand(0,255));
        }
        $appKey = 'base64:'.base64_encode($appKey);
        $file = $this->basePath('.env');
        $lines = $this->parseEnvFile($file);
        $flag = false;
        foreach($lines as $i => $line) {
            $lines[$i] = trim($line);
            $lines[$i] = trim($line, "\n");
            if(strpos($line, 'APP_KEY') !== false) {
                $data = explode('=', $line, 2);
                if(!isset($data[1]) || trim($data[1]) == '') {
                    $lines[$i] = "APP_KEY=".$appKey;
                    $flag = true;
                }
            }
        }
        if($flag == false) {
            $lines = ["APP_KEY=".$appKey] + $lines;
        }
        $data = implode("\n", $lines);
        if(file_put_contents($file, $data)) {
            putenv("APP_KEY=$appKey");
            $_ENV['APP_KEY'] = $appKey;
            $_SERVER['APP_KEY'] = $appKey;
            return true;
        }
        else {
            throw new Exception('Failed to write in .env file.');
        }
    }
public function setKey()
    {
        if(trim(env('APP_KEY')) != '') {
            return true;
        }
        $appKey='';
        for($i=0;$i<32;$i++) {
            $appKey.=chr(rand(0,255));
        }
        $appKey = 'base64:'.base64_encode($appKey);
        $file = $this->basePath('.env');
        $lines = $this->parseEnvFile($file);
        $flag = false;
        foreach($lines as $i => $line) {
            $lines[$i] = trim($line);
            $lines[$i] = trim($line, "\n");
            if(strpos($line, 'APP_KEY') !== false) {
                $data = explode('=', $line, 2);
                if(!isset($data[1]) || trim($data[1]) == '') {
                    $lines[$i] = "APP_KEY=".$appKey;
                    $flag = true;
                }
            }
        }
        if($flag == false) {
            $lines = ["APP_KEY=".$appKey] + $lines;
        }
        $data = implode("\n", $lines);
        if(file_put_contents($file, $data)) {
            putenv("APP_KEY=$appKey");
            $_ENV['APP_KEY'] = $appKey;
            $_SERVER['APP_KEY'] = $appKey;
            return true;
        }
        else {
            throw new Exception('Failed to write in .env file.');
        }
    }
public function setKey ( ) { if ( trim ( env ( 'APP_KEY' ) ) != '' ) { return true ; } $ appKey = '' ; for ( $ i = 0 ; $ i < 32 ; $ i ++ ) { $ appKey .= chr ( rand ( 0 , 255 ) ) ; } $ appKey = 'base64:' . base64_encode ( $ appKey ) ; $ file = $ this -> basePath ( '.env' ) ; $ lines = $ this -> parseEnvFile ( $ file ) ; $ flag = false ; foreach ( $ lines as $ i => $ line ) { $ lines [ $ i ] = trim ( $ line ) ; $ lines [ $ i ] = trim ( $ line , "\n" ) ; if ( strpos ( $ line , 'APP_KEY' ) !== false ) { $ data = explode ( '=' , $ line , 2 ) ; if ( ! isset ( $ data [ 1 ] ) || trim ( $ data [ 1 ] ) == '' ) { $ lines [ $ i ] = "APP_KEY=" . $ appKey ; $ flag = true ; } } } if ( $ flag == false ) { $ lines = [ "APP_KEY=" . $ appKey ] + $ lines ; } $ data = implode ( "\n" , $ lines ) ; if ( file_put_contents ( $ file , $ data ) ) { putenv ( "APP_KEY=$appKey" ) ; $ _ENV [ 'APP_KEY' ] = $ appKey ; $ _SERVER [ 'APP_KEY' ] = $ appKey ; return true ; } else { throw new Exception ( 'Failed to write in .env file.' ) ; } }
Set Application secret key.

@return string
@throws  Exception
Set Application secret key .