Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Prompts Laravel Package

laravel/prompts

Laravel Prompts adds beautiful, user-friendly interactive forms to PHP CLI apps and Artisan commands. It supports placeholder text, validation, and a browser-like input experience, making it easy to collect and validate user input in the terminal.

View on GitHub
Deep Wiki
Context7

Laravel Prompts is a PHP package for building beautiful, user-friendly interactive CLI forms with browser-like niceties such as placeholders and validation. It’s ideal for collecting input in Laravel Artisan commands, while remaining flexible enough to use in any command-line PHP project.

Designed to make terminal UX feel modern and consistent, Prompts helps you guide users through structured input with clear feedback and sensible defaults.

  • Interactive prompts for richer command-line workflows
  • Validation with immediate error feedback
  • Placeholder text and helpful hints
  • Works seamlessly with Artisan console commands
  • Usable in non-Laravel PHP CLI applications
Frequently asked questions about Prompts
How do I install Laravel Prompts in a Laravel project?
Run `composer require laravel/prompts` in your project directory. No additional configuration is needed—it integrates directly with Laravel’s Artisan commands and uses Symfony’s Console component under the hood.
Can I use Laravel Prompts in non-Laravel PHP CLI scripts?
Yes, Laravel Prompts works standalone in any PHP CLI project. Just install it via Composer (`composer require laravel/prompts`) and use the `Prompt` facade or namespace imports. It’s framework-agnostic beyond Laravel’s native Artisan support.
What Laravel and PHP versions does Prompts support?
Laravel Prompts requires Laravel 10+ and PHP 8.1+. It’s tested against the latest stable releases, and the team ensures backward compatibility for minor Laravel updates. Check the [GitHub releases](https://github.com/laravel/prompts/releases) for version-specific notes.
How do I validate user input in Prompts like Laravel’s web validation?
Use Laravel’s validation rules (e.g., `required`, `email`) or Symfony’s validators directly. For example: `Prompt::text('Email', ['required', 'email'])` or `Prompt::select('Role', ['admin', 'user'], ['required'])` with custom messages. Errors display inline in the terminal.
Does Prompts work in CI/CD pipelines or non-interactive environments?
Yes, Prompts supports non-interactive mode via `--non-interactive` flag or `Prompt::nonInteractive()`. It skips prompts and returns default values, making it safe for CI/CD. Useful for automated deployments or scripts where user input isn’t needed.
How do I create multi-step forms with conditional logic?
Use `FormStep::conditional()` to show/hide prompts based on previous answers. For example, if a user selects 'Yes' to a confirm prompt, the next step might reveal advanced settings. Each step is a method call in your command’s `handle()` method, chained or stored in variables.
Are there performance concerns with complex Prompts forms?
Prompts is lightweight (~1MB) and optimized for CLI use, but complex forms with many dynamic elements (e.g., DataTables) may introduce slight rendering delays. For bulk operations, consider batching prompts or using `Prompt::spin()` to show loading states during async tasks.
How do I test Prompts in PHPUnit or Pest?
Mock terminal input using Symfony’s `ConsoleTestCase` or libraries like `symfony/console` test helpers. For example, override `getHelperSet()` to inject a `QuestionHelper` with predefined answers. Avoid testing UI rendering; focus on logic and output validation.
What are the alternatives to Laravel Prompts for CLI forms?
For Laravel, alternatives include Symfony’s `QuestionHelper` (built-in) or third-party packages like `symfony/console` (more low-level) or `laravel-zero/framework` (for standalone CLI apps). For richer UIs, consider `symfony/ux` or `reactphp/cli`. Prompts stands out for its browser-like UX and Laravel-native integration.
How do I handle ANSI/terminal compatibility issues (e.g., Windows CMD)?
Prompts relies on ANSI escape codes for styling and interactivity. For legacy terminals (e.g., Windows CMD), enable fallbacks by setting `Prompt::disableAnsi()` or use libraries like `symfony/console`’s `Output::setDecorated(false)`. Test in your target environments early to avoid runtime issues.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport