Laravel Console WIzzard is a package for creating multi-step wizards with complex input inside the console. Its primary purpose is to collect data for file generators—here’s an example from the project’s readme:
1namespace App\Console\Commands; 2 3use Shomisha\LaravelConsoleWizard\Command\Wizard; 4use Shomisha\LaravelConsoleWizard\Steps\ChoiceStep; 5use Shomisha\LaravelConsoleWizard\Steps\TextStep; 6 7class IntroductionWizard extends Wizard 8{ 9 protected $signature = "wizard:introduction";10 11 protected $description = 'Introduction wizard.';12 13 public function getSteps(): array14 {15 return [16 'name' => new TextStep("What's your name?"),17 'age' => new TextStep("How old are you?"),18 'gender' => new ChoiceStep("Your gender?", ["Male", "Female"]),19 ];20 }21 22 public function completed()23 {24 $this->line(sprintf(25 "This is %s and %s is %s years old.",26 $this->answers->get('name'),27 ($this->answers->get('gender') === 'Male') ? 'he' : 'she',28 $this->answers->get('age')29 ));30 }31}
This package works by defining a set of steps and then once completed, you can process data for output, generate files, or perform whatever you need to with the data.
- TextStep – expects a text input answer (i.e., name)
- MultipleAnswerTextStep – similar to TextStep, except it takes multiple answers and returns them in an array
- ChoiceStep – this allows a user to pick one answer from multiple choices
- MultipleChoiceStep – similar to ChoiceStep, but allows the user to pick multiple choices and returns the values as an array
- UniqueMultipleChoiceStep – just like MultipleChoiceStep, but does not allow a user to select a single choice more than once
- ConfirmStep – the user confirms yes or no, and this step returns a
Boolean
.
Learn More
You can learn more about this package, get full installation instructions, and view the source code on GitHub. This package also has a wiki providing in-depth documentation on step types, validation, and using the package.
0 comments:
Post a Comment
Thanks