Skip to main content

Introduction

Laravel Prompts is a PHP package for adding beautiful and user-friendly forms to your command-line applications. It provides browser-like features such as placeholder text, validation, and styled output. Laravel Prompts is ideal for accepting user input inside Artisan console commands, but it can be used in any command-line PHP project.
Laravel Prompts supports macOS, Linux, and Windows with WSL. In unsupported environments it falls back automatically to simpler input methods.

Installation

Laravel Prompts ships with Laravel and requires no additional installation. To use it in a standalone PHP project, install via Composer:

Available prompt functions

text — free text input

text() prompts the user for a string and returns the value.
Add a placeholder, default value, and hint:
Make the field required and customize the error message:
Add custom validation logic with a closure:
You can also pass Laravel validation rules as an array:

textarea — multi-line input

textarea() accepts multi-line input.

number — numeric input

number() accepts a numeric value. The user can also use arrow keys to increase or decrease the number.

password — masked input

password() behaves like text() but masks the typed characters.

confirm — yes/no confirmation

confirm() asks a yes/no question and returns true or false.
Customize the default value and button labels:

select — single-choice list

select() presents a list and returns the chosen value.
Use an associative array to return a key instead of a display label:
Control how many options are visible before scrolling with the scroll argument (default is 5).

multiselect — multiple-choice list

multiselect() lets the user select one or more options. It returns an array.

suggest — autocomplete input

suggest() shows suggestions while still accepting any input.
Pass a closure to provide dynamic suggestions based on what the user has typed so far.
search() filters a list in real time as the user types.

multisearch — dynamic multi-select

multisearch() combines dynamic search with multiple selection.

pause — wait for keypress

pause() displays a message and waits for the user to press Enter.

autocomplete — inline completion

autocomplete() provides inline ghost-text completion. Matching suggestions appear as users type and can be accepted by pressing Tab or the right arrow key. Unlike suggest(), the user is encouraged to choose from the provided options.
Add a placeholder, default value, and hint:
Pass a closure to generate options dynamically based on what the user has typed:

Validation

Every prompt function accepts a validate argument for custom validation logic. Return an error message string on failure, or null on success.

Transforming input before validation

Use the transform argument to modify the input before validation runs.

Forms

form() groups multiple prompts so the user can go back and edit answers before submitting. If the user cancels, all prompts exit together.

Informational messages

Display styled messages without prompting for input.

Callouts

callout() displays a boxed message with a label and content — ideal for surfacing important information such as deployment summaries, error details, or status updates.
Pass 'warning' or 'error' as the type argument to change the visual style.
The info argument adds a footer line — useful for displaying metadata like IDs or timestamps.

Rich content

Instead of a string, pass an array to build rich, structured callouts. The Element class provides factory methods for headings, bulleted lists, numbered lists, and key-value lists.
Use Element::keyValueList to display labeled data:
The Element::link method creates a clickable hyperlink in terminals that support OSC 8. You may provide a URL alone, or a URL with a custom label:
If no label is provided, the URL itself will be displayed as the link text.

Tables

Display rows of data in a formatted table.

Spin (loading indicator)

spin() displays a spinner while a callback runs.
spin() requires the pcntl PHP extension. Without it, no spinner is shown but the callback still runs.

Progress bar

progress() displays a progress bar while iterating over items.
For manual control, use the start/advance/finish API.

Task

task() displays a labeled task with a spinner and a scrolling live output area while a given callback is executing. It is ideal for wrapping long-running processes such as dependency installation or deployment scripts, providing real-time visibility into what is happening.
The callback receives a Logger instance that you can use to display log lines and status messages in real time.
task() requires the pcntl PHP extension to animate the spinner. Without it, a static version of the task will appear instead.

Logging lines

The line method writes a single log line to the scrolling output area:

Status messages

Use success, warning, and error to display stable highlighted messages above the scrolling log area:

Updating the label

The label method updates the task’s label while it is running, and subLabel displays a dim line beneath it for ephemeral status messages. Pass an empty string to clear the sub-label:

Streaming text

For processes that produce output incrementally — such as AI-generated responses — the partial method streams text word-by-word or chunk-by-chunk. Call commitPartial when the stream is complete:

Customizing output limit and keeping the summary

By default the task displays up to 10 lines of scrolling output. Customize this with the limit argument. To keep the status messages on screen after the task finishes, pass keepSummary: true:

Stream

stream() displays text that streams into the terminal incrementally — ideal for AI-generated content or any chunked output.
The append method adds text to the stream with a gradual fade-in effect. Call close when all content has been streamed to finalize the output and restore the cursor.

Terminal utilities

Terminal title

Pass an empty string to reset the terminal title to its default:

Clear the terminal

Terminal considerations

Terminal width: Labels, options, and validation messages that exceed the terminal column width are automatically truncated. Aim for a maximum of 74 characters to safely support 80-column terminals. Terminal height: For prompts that accept the scroll argument, the configured value is automatically reduced to fit the terminal height, including space for a validation message.

Unsupported environments and fallbacks

In environments that don’t support the advanced rendering (such as Windows without WSL), Laravel Prompts automatically falls back to simpler input methods compatible with the host terminal. No code changes are required.

Testing

Fake prompt input in tests using Prompt::fake().
When using Laravel’s Artisan test helpers, you can also assert against informational output functions:

Artisan console

Use Prompts inside Artisan commands
Last modified on July 1, 2026