protected function setupEnvFile()
    {
        $env    = __DIR__ . '/stubs/env.stub';
        $config = $this->database;

        // Update the env stub file with actual credentials.
        $contents = str_replace(
          array_map(function ($key) {
              return '{{' . $key . '}}';
          }, array_keys($config)),
          array_values($config),
          $this->laravel['files']->get($env)
        );

        // Generate a key
        $contents = str_replace('{{key}}', Str::random(32), $contents);

        // Check if we can actually write the environment file.
        if ($this->laravel['files']->put(($envFile = $this->laravel['path.base'] . '/.env'),
            $contents) === false
        ) {
            throw new \RuntimeException("Could not write env file to [$envFile].");
        }

        // Reload env file
        $this->laravel['Illuminate\Foundation\Bootstrap\DetectEnvironment']->bootstrap($this->laravel);

        // Reload config
        $this->laravel['Illuminate\Foundation\Bootstrap\LoadConfiguration']->bootstrap($this->laravel);

    }