App\Http\Controllers\AppController::doSetup PHP Method

doSetup() public method

public doSetup ( )
    public function doSetup()
    {
        if (Utils::isNinjaProd()) {
            return Redirect::to('/');
        }
        $valid = false;
        $test = Input::get('test');
        $app = Input::get('app');
        $app['key'] = env('APP_KEY') ?: str_random(RANDOM_KEY_LENGTH);
        $app['debug'] = Input::get('debug') ? 'true' : 'false';
        $database = Input::get('database');
        $dbType = 'mysql';
        // $database['default'];
        $database['connections'] = [$dbType => $database['type']];
        $mail = Input::get('mail');
        $email = $mail['username'];
        $mail['from']['address'] = $email;
        if ($test == 'mail') {
            return self::testMail($mail);
        }
        $valid = self::testDatabase($database);
        if ($test == 'db') {
            return $valid === true ? 'Success' : $valid;
        } elseif (!$valid) {
            return Redirect::to('/setup')->withInput();
        }
        if (Utils::isDatabaseSetup() && Account::count() > 0) {
            return Redirect::to('/');
        }
        $_ENV['APP_ENV'] = 'production';
        $_ENV['APP_DEBUG'] = $app['debug'];
        $_ENV['APP_URL'] = $app['url'];
        $_ENV['APP_KEY'] = $app['key'];
        $_ENV['APP_CIPHER'] = env('APP_CIPHER', 'AES-256-CBC');
        $_ENV['DB_TYPE'] = $dbType;
        $_ENV['DB_HOST'] = $database['type']['host'];
        $_ENV['DB_DATABASE'] = $database['type']['database'];
        $_ENV['DB_USERNAME'] = $database['type']['username'];
        $_ENV['DB_PASSWORD'] = $database['type']['password'];
        $_ENV['MAIL_DRIVER'] = $mail['driver'];
        $_ENV['MAIL_PORT'] = $mail['port'];
        $_ENV['MAIL_ENCRYPTION'] = $mail['encryption'];
        $_ENV['MAIL_HOST'] = $mail['host'];
        $_ENV['MAIL_USERNAME'] = $mail['username'];
        $_ENV['MAIL_FROM_NAME'] = $mail['from']['name'];
        $_ENV['MAIL_PASSWORD'] = $mail['password'];
        $_ENV['PHANTOMJS_CLOUD_KEY'] = 'a-demo-key-with-low-quota-per-ip-address';
        $_ENV['MAILGUN_DOMAIN'] = $mail['mailgun_domain'];
        $_ENV['MAILGUN_SECRET'] = $mail['mailgun_secret'];
        $config = '';
        foreach ($_ENV as $key => $val) {
            if (is_array($val)) {
                continue;
            }
            if (preg_match('/\\s/', $val)) {
                $val = "'{$val}'";
            }
            $config .= "{$key}={$val}\n";
        }
        // Write Config Settings
        $fp = fopen(base_path() . '/.env', 'w');
        fwrite($fp, $config);
        fclose($fp);
        // == DB Migrate & Seed == //
        // Artisan::call('migrate:rollback', array('--force' => true)); // Debug Purposes
        Artisan::call('migrate', ['--force' => true]);
        if (Industry::count() == 0) {
            Artisan::call('db:seed', ['--force' => true]);
        }
        Cache::flush();
        Artisan::call('optimize', ['--force' => true]);
        $firstName = trim(Input::get('first_name'));
        $lastName = trim(Input::get('last_name'));
        $email = trim(strtolower(Input::get('email')));
        $password = trim(Input::get('password'));
        $account = $this->accountRepo->create($firstName, $lastName, $email, $password);
        $user = $account->users()->first();
        return Redirect::to('/login');
    }