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.
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.
select — single-choice list
select() presents a list and returns the chosen value.
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.
search — dynamic search
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.
Validation
Every prompt function accepts avalidate argument for custom validation logic. Return an error message string on failure, or null on success.
Transforming input before validation
Use thetransform 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.
'warning' or 'error' as the type argument to change the visual style.
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. TheElement class provides factory methods for headings, bulleted lists, numbered lists, and key-value lists.
Element::keyValueList to display labeled data:
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:
Tables
Display rows of data in a formatted table.Spin (loading indicator)
spin() displays a spinner while a callback runs.
Progress bar
progress() displays a progress bar while iterating over items.
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.
Logger instance that you can use to display log lines and status messages in real time.
Logging lines
Theline method writes a single log line to the scrolling output area:
Status messages
Usesuccess, warning, and error to display stable highlighted messages above the scrolling log area:
Updating the label
Thelabel 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 — thepartial 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 thelimit 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.
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
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 thescroll 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 usingPrompt::fake().
Related pages
Artisan console
Use Prompts inside Artisan commands