/** * Handles the configuration and installation of Platform. * * @return mixed */ public function configure() { $this->installer->setUserData(request()->input('user', [])); $this->installer->setDatabaseData($driver = request()->input('database.driver'), request()->input("database.{$driver}", [])); $messages = $this->installer->validate(); if (!$messages->isEmpty()) { return redirect()->back()->withLicense(true)->withInput()->withErrors($messages); } try { $this->installer->install(); } catch (\Exception $e) { return redirect()->back()->withLicense(true)->withInput()->withErrors($e->getMessage()); } return redirect('installer/complete'); }
/** * Prompts the user for the database credentials. * * @return void */ protected function askDatabaseDetails() { $this->output->writeln(<<<STEP <fg=yellow> *-----------------------------------------------* | | | Step #1: Configure Database | | | *-----------------------------------------------* </fg=yellow> STEP ); // Get all the available database drivers $drivers = $this->installer->getDatabaseDrivers(); // Ask the user to select the database driver $driver = $this->askDatabaseDriver($drivers); // Hold the database details $databaseData = []; // Loop through the selected driver fields foreach ($drivers[$driver] as $field => $config) { // Prepare the field name to avoid confusion $fieldName = $field === 'database' ? 'name' : $field; // Determine if the field output should be hidden $isHidden = $field === 'password'; // Prepare the question message if ($value = $config['value']) { $question = sprintf('<fg=green>Please enter the database</fg=green> [%s] (enter for [%s]): ', $fieldName, $config['value']); } else { $question = sprintf('<fg=green>Please enter the database</fg=green> [%s]: ', $fieldName); } // Prepare the question validator $validator = function ($answer) use($fieldName, $config) { if (!$answer && $config['rules'] === 'required') { throw new \RuntimeException("The database '{$fieldName}' field is required!"); } return $answer; }; // Ask the question to the user and store the answer $databaseData[$field] = $this->askQuestion($question, $config['value'], $isHidden, $validator); } $this->installer->setDatabaseData($driver, $databaseData); }