Elevating the CLI Experience Laravel Prompts transforms the traditionally sterile environment of command-line tools into a modern, interactive interface. While Laravel has long supported console commands via Artisan, this package introduces a polished aesthetic with borders, hints, and real-time validation. It shifts the developer focus from merely capturing input to guiding the user through a structured workflow. Prerequisites & Tools To get started, you should have a functional PHP environment and a Laravel project installed. Familiarity with Artisan commands is essential, as you will be implementing these prompts within the `handle()` method of your command classes. The core library is `laravel/prompts`, which provides the functional API used throughout this guide. Implementation Walkthrough Using the `text` function creates a clean input field. Unlike the standard `ask` method, `text` supports advanced metadata like placeholders and hints. ```php use function Laravel\Prompts\text; $name = text( label: 'What is the backup name?', placeholder: 'e.g. daily_backup', hint: 'This will be the filename suffix.', required: true ); ``` For more complex interactions, the `multiselect` function allows users to toggle multiple options using the spacebar, returning an array of selected values. This is perfect for defining backup scopes like databases, files, or media assets. ```php use function Laravel\Prompts\multiselect; $categories = multiselect( label: 'What should we include?', options: ['Database', 'Files', 'Media'], default: ['Database'] ); ``` Input Validation and Defaults Reliable CLI tools must prevent bad data. Laravel Prompts allows you to pass a closure to the `validate` parameter. If the logic returns a string, the CLI displays it as a red error message, keeping the user in the prompt until they provide valid data. Combining this with `default` values—such as a timestamped string—drastically reduces the friction for end-users running routine tasks. Tips and Best Practices Always use named arguments to keep your prompt definitions readable. When building tools for other developers, leverage the `hint` parameter to explain specific requirements, such as character limits or file formats. This documentation-in-terminal approach reduces the need for external manuals and prevents "trial and error" execution.
Laravel Prompts
Products
TL;DR
The Laravel channel (5 mentions) celebrates the tool in 'Prompts - CLI beauty for Laravel' and 'Build Your First CLI App with Laravel Prompts' because it brings browser-like interactivity to terminal environments.
- Dec 2, 2025
- Aug 14, 2024
- Aug 7, 2024
- Jul 16, 2024
- Jul 27, 2023