Laravel - Artisan Console - Multiple Choice Questions
If you need to give the user a predefined set of choices when asking a question, you may use the choice
method. You may set the array index of the default value to be returned if no option is chosen by passing the index as the third argument to the method:
$name = $this->choice(
'What is your name?',
['Taylor', 'Dayle'],
$defaultIndex
);
In addition, the choice
method accepts optional fourth and fifth arguments for determining the maximum number of attempts to select a valid response and whether multiple selections are permitted:
$name = $this->choice(
'What is your name?',
['Taylor', 'Dayle'],
$defaultIndex,
$maxAttempts = null,
$allowMultipleSelections = false
);