Skip to content

Commit

Permalink
Document closure as second parameter
Browse files Browse the repository at this point in the history
- Anticipate can now accept a closure as a second parameter instead of an array, as of 6.0
  • Loading branch information
AndrewFeeney authored Oct 28, 2019
1 parent bd05054 commit 96e71a7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion artisan.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- [Writing Commands](#writing-commands)
- [Generating Commands](#generating-commands)
- [Command Structure](#command-structure)
- [Closure Commands](#closure-commands)
- [Commands](#closure-commands)
- [Defining Input Expectations](#defining-input-expectations)
- [Arguments](#arguments)
- [Options](#options)
Expand Down Expand Up @@ -331,6 +331,12 @@ If you need to ask the user for a simple confirmation, you may use the `confirm`
The `anticipate` method can be used to provide auto-completion for possible choices. The user can still choose any answer, regardless of the auto-completion hints:

$name = $this->anticipate('What is your name?', ['Taylor', 'Dayle']);

Alternatively, you may pass a closure instead of an array as the second parameter. This closure will be called each time the user types a character into the input. It should accept a string parameter containing the user's input so far, and return an array of options for autocompletion. This is useful when you need to generate the autocompletion options dynamically based on the user's input, rather than upfront.

$name = $this->anticipate('What is your name?', function ($input) {
return $this->externalService->getFilteredNames($input)->toArray();
});

#### Multiple Choice Questions

Expand Down

0 comments on commit 96e71a7

Please sign in to comment.