- How do I use Laravel Prompts in a Laravel Artisan command?
- Install via Composer (`composer require laravel/prompts`), then use methods like `Prompt::text()`, `Prompt::select()`, or `Prompt::confirm()` in your command’s `handle()` method. For example, `Prompt::text('Enter name', ['required' => true])` collects input with validation. Works seamlessly with Laravel’s Artisan framework.
- Does Laravel Prompts support validation like Laravel’s Form Requests?
- Yes. Use `Prompt::text()->validateWith()` to pass Laravel validation rules (e.g., `['required', 'email']`) or custom callables. It integrates with Laravel’s validation system, so you can reuse existing rules or write new ones for CLI inputs.
- Can I use Laravel Prompts in non-Laravel PHP CLI tools?
- Absolutely. Laravel Prompts relies on Symfony Console, so it works in any PHP CLI project. Install it via Composer, then use the same methods (e.g., `Prompt::select()`) in standalone scripts or libraries. No Laravel dependencies are required beyond Symfony Console.
- What Laravel versions are compatible with Laravel Prompts?
- Laravel Prompts supports Laravel 10.x and 11.x. It also works with PHP 8.1+ standalone (non-Laravel) projects. Check the [latest release notes](https://github.com/laravel/prompts/releases) for version-specific details or breaking changes.
- How do I test interactive prompts in CI/CD pipelines?
- Use `Prompt::fake()` to mock prompts in PHPUnit or Pest tests. For example, `Prompt::fake(['name' => 'test']);` simulates user input. This lets you test validation and logic without manual CLI interaction, making it ideal for automated workflows.
- Are there alternatives to Laravel Prompts for CLI forms?
- Yes. For Laravel, consider Symfony Console’s built-in methods (e.g., `$helper->choice()`), but they lack browser-like UX features. For PHP, alternatives include `symfony/console` (basic), `react/prompts` (more advanced), or `laravel/framework`’s native helpers. Laravel Prompts stands out for its validation, placeholders, and Artisan integration.
- How do I handle multiline text input or password fields?
- Use `Prompt::text()->password()` for masked input (e.g., passwords) or `Prompt::text()->multiline()` for paragraphs. Both support validation and placeholders. For example: `Prompt::text('Enter notes')->multiline()->validateWith(['required'])`.
- Can I customize the appearance of prompts (colors, styles)?
- Yes. Laravel Prompts uses Symfony Console’s style system, so you can override colors, padding, or formatting via `$prompt->style()` or by extending the `Prompt` class. For example, `Prompt::text()->style('warning')` changes the text color. Check the [documentation](https://laravel.com/docs/prompts) for styling options.
- Does Laravel Prompts work in Windows Terminal or WSL?
- Yes, Laravel Prompts is cross-platform and tested on Windows Terminal, WSL, Linux, and macOS. It handles multibyte strings and edge cases (e.g., ANSI escape sequences) gracefully. For older terminals, fallbacks ensure basic functionality.
- How do I disable prompts in non-interactive environments (e.g., CI)?
- Use the `--non-interactive` flag in your command’s definition (e.g., `php artisan my:command --non-interactive`). This skips prompts and uses defaults or fails gracefully. Alternatively, check `Prompt::isInteractive()` in code to conditionally bypass prompts.