- 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.