class FormBuilder

Properties

protected FormStep> $steps

Each step that should be executed.

protected mixed[] $responses

The responses provided by each step.

Methods

add(Closure $step, string|null $name = null, bool $ignoreWhenReverting = false)

Add a new step.

addIf(bool|Closure $condition, Closure $step, string|null $name = null, bool $ignoreWhenReverting = false)

Add a new conditional step.

array
submit()

Run all of the given steps.

text(string $label, string $placeholder = '', string $default = '', bool|string $required = false, mixed $validate = null, string $hint = '', string|null $name = null, Closure|null $transform = null)

Prompt the user for text input.

textarea(string $label, string $placeholder = '', string $default = '', bool|string $required = false, Closure|null $validate = null, string $hint = '', int $rows = 5, string|null $name = null, Closure|null $transform = null)

Prompt the user for multiline text input.

password(string $label, string $placeholder = '', bool|string $required = false, mixed $validate = null, string $hint = '', string|null $name = null, Closure|null $transform = null)

Prompt the user for input, hiding the value.

select(string $label, array|Collection $options, int|string|null $default = null, int $scroll = 5, mixed $validate = null, string $hint = '', bool|string $required = true, string|null $name = null, Closure|null $transform = null)

Prompt the user to select an option.

multiselect(string $label, array|Collection $options, array|Collection $default = [], int $scroll = 5, bool|string $required = false, mixed $validate = null, string $hint = 'Use the space bar to select options.', string|null $name = null, Closure|null $transform = null)

Prompt the user to select multiple options.

confirm(string $label, bool $default = true, string $yes = 'Yes', string $no = 'No', bool|string $required = false, mixed $validate = null, string $hint = '', string|null $name = null, Closure|null $transform = null)

Prompt the user to confirm an action.

pause(string $message = 'Press enter to continue...', string|null $name = null)

Prompt the user to continue or cancel after pausing.

suggest(string $label, array|Closure|Collection $options, string $placeholder = '', string $default = '', int $scroll = 5, bool|string $required = false, mixed $validate = null, string $hint = '', string|null $name = null, Closure|null $transform = null)

Prompt the user for text input with auto-completion.

search(string $label, Closure $options, string $placeholder = '', int $scroll = 5, mixed $validate = null, string $hint = '', bool|string $required = true, string|null $name = null, Closure|null $transform = null)

Allow the user to search for an option.

multisearch(string $label, Closure $options, string $placeholder = '', int $scroll = 5, bool|string $required = false, mixed $validate = null, string $hint = 'Use the space bar to select options.', string|null $name = null, Closure|null $transform = null)

Allow the user to search for multiple option.

spin(Closure $callback, string $message = '', string|null $name = null)

Render a spinner while the given callback is executing.

note(string $message, string|null $type = null, string|null $name = null)

Display a note.

error(string $message, string|null $name = null)

Display an error.

warning(string $message, string|null $name = null)

Display a warning.

alert(string $message, string|null $name = null)

Display an alert.

info(string $message, string|null $name = null)

Display an informational message.

intro(string $message, string|null $name = null)

Display an introduction.

outro(string $message, string|null $name = null)

Display a closing message.

table(array|Collection $headers = [], array|Collection|null $rows = null, string|null $name = null)

Display a table.

progress(string $label, int|iterable $steps, Closure|null $callback = null, string $hint = '', string|null $name = null)

Display a progress bar.

runPrompt(callable $prompt, array $arguments, bool $ignoreWhenReverting = false)

Execute the given prompt passing the given arguments.

Details

at line 30
FormBuilder add(Closure $step, string|null $name = null, bool $ignoreWhenReverting = false)

Add a new step.

Parameters

Closure $step
string|null $name
bool $ignoreWhenReverting

Return Value

FormBuilder

at line 40
FormBuilder addIf(bool|Closure $condition, Closure $step, string|null $name = null, bool $ignoreWhenReverting = false)

Add a new conditional step.

Parameters

bool|Closure $condition
Closure $step
string|null $name
bool $ignoreWhenReverting

Return Value

FormBuilder

at line 52
array submit()

Run all of the given steps.

Return Value

array

at line 93
FormBuilder text(string $label, string $placeholder = '', string $default = '', bool|string $required = false, mixed $validate = null, string $hint = '', string|null $name = null, Closure|null $transform = null)

Prompt the user for text input.

Parameters

string $label
string $placeholder
string $default
bool|string $required
mixed $validate
string $hint
string|null $name
Closure|null $transform

Return Value

FormBuilder

at line 101
FormBuilder textarea(string $label, string $placeholder = '', string $default = '', bool|string $required = false, Closure|null $validate = null, string $hint = '', int $rows = 5, string|null $name = null, Closure|null $transform = null)

Prompt the user for multiline text input.

Parameters

string $label
string $placeholder
string $default
bool|string $required
Closure|null $validate
string $hint
int $rows
string|null $name
Closure|null $transform

Return Value

FormBuilder

at line 109
FormBuilder password(string $label, string $placeholder = '', bool|string $required = false, mixed $validate = null, string $hint = '', string|null $name = null, Closure|null $transform = null)

Prompt the user for input, hiding the value.

Parameters

string $label
string $placeholder
bool|string $required
mixed $validate
string $hint
string|null $name
Closure|null $transform

Return Value

FormBuilder

at line 120
FormBuilder select(string $label, array|Collection $options, int|string|null $default = null, int $scroll = 5, mixed $validate = null, string $hint = '', bool|string $required = true, string|null $name = null, Closure|null $transform = null)

Prompt the user to select an option.

Parameters

string $label
array|Collection $options
int|string|null $default
int $scroll
mixed $validate
string $hint
bool|string $required
string|null $name
Closure|null $transform

Return Value

FormBuilder

at line 131
FormBuilder multiselect(string $label, array|Collection $options, array|Collection $default = [], int $scroll = 5, bool|string $required = false, mixed $validate = null, string $hint = 'Use the space bar to select options.', string|null $name = null, Closure|null $transform = null)

Prompt the user to select multiple options.

Parameters

string $label
array|Collection $options
array|Collection $default
int $scroll
bool|string $required
mixed $validate
string $hint
string|null $name
Closure|null $transform

Return Value

FormBuilder

at line 139
FormBuilder confirm(string $label, bool $default = true, string $yes = 'Yes', string $no = 'No', bool|string $required = false, mixed $validate = null, string $hint = '', string|null $name = null, Closure|null $transform = null)

Prompt the user to confirm an action.

Parameters

string $label
bool $default
string $yes
string $no
bool|string $required
mixed $validate
string $hint
string|null $name
Closure|null $transform

Return Value

FormBuilder

at line 147
FormBuilder pause(string $message = 'Press enter to continue...', string|null $name = null)

Prompt the user to continue or cancel after pausing.

Parameters

string $message
string|null $name

Return Value

FormBuilder

at line 157
FormBuilder suggest(string $label, array|Closure|Collection $options, string $placeholder = '', string $default = '', int $scroll = 5, bool|string $required = false, mixed $validate = null, string $hint = '', string|null $name = null, Closure|null $transform = null)

Prompt the user for text input with auto-completion.

Parameters

string $label
array|Closure|Collection $options
string $placeholder
string $default
int $scroll
bool|string $required
mixed $validate
string $hint
string|null $name
Closure|null $transform

Return Value

FormBuilder

Allow the user to search for an option.

Parameters

string $label
Closure $options
string $placeholder
int $scroll
mixed $validate
string $hint
bool|string $required
string|null $name
Closure|null $transform

Return Value

FormBuilder

at line 178
FormBuilder multisearch(string $label, Closure $options, string $placeholder = '', int $scroll = 5, bool|string $required = false, mixed $validate = null, string $hint = 'Use the space bar to select options.', string|null $name = null, Closure|null $transform = null)

Allow the user to search for multiple option.

Parameters

string $label
Closure $options
string $placeholder
int $scroll
bool|string $required
mixed $validate
string $hint
string|null $name
Closure|null $transform

Return Value

FormBuilder

at line 188
FormBuilder spin(Closure $callback, string $message = '', string|null $name = null)

Render a spinner while the given callback is executing.

Parameters

Closure $callback
string $message
string|null $name

Return Value

FormBuilder

at line 196
FormBuilder note(string $message, string|null $type = null, string|null $name = null)

Display a note.

Parameters

string $message
string|null $type
string|null $name

Return Value

FormBuilder

at line 204
FormBuilder error(string $message, string|null $name = null)

Display an error.

Parameters

string $message
string|null $name

Return Value

FormBuilder

at line 212
FormBuilder warning(string $message, string|null $name = null)

Display a warning.

Parameters

string $message
string|null $name

Return Value

FormBuilder

at line 220
FormBuilder alert(string $message, string|null $name = null)

Display an alert.

Parameters

string $message
string|null $name

Return Value

FormBuilder

at line 228
FormBuilder info(string $message, string|null $name = null)

Display an informational message.

Parameters

string $message
string|null $name

Return Value

FormBuilder

at line 236
FormBuilder intro(string $message, string|null $name = null)

Display an introduction.

Parameters

string $message
string|null $name

Return Value

FormBuilder

at line 244
FormBuilder outro(string $message, string|null $name = null)

Display a closing message.

Parameters

string $message
string|null $name

Return Value

FormBuilder

at line 255
FormBuilder table(array|Collection $headers = [], array|Collection|null $rows = null, string|null $name = null)

Display a table.

Parameters

array|Collection $headers
array|Collection|null $rows
string|null $name

Return Value

FormBuilder

at line 269
FormBuilder progress(string $label, int|iterable $steps, Closure|null $callback = null, string $hint = '', string|null $name = null)

Display a progress bar.

Parameters

string $label
int|iterable $steps
Closure|null $callback
string $hint
string|null $name

Return Value

FormBuilder

at line 279
protected FormBuilder runPrompt(callable $prompt, array $arguments, bool $ignoreWhenReverting = false)

Execute the given prompt passing the given arguments.

Parameters

callable $prompt
array $arguments
bool $ignoreWhenReverting

Return Value

FormBuilder