Laravel Prompts: Beautiful CLI
Laravel Prompts: Beautiful CLI
Laravel Prompts: Beautiful CLI
Tip: Text Prompt
$name = text('What is your name?');
Gotcha: Select Prompt
$role = select('Select a role', ['admin', 'user', 'moderator']);
Tip: Multiselect
$permissions = multiselect('Select permissions', ['read', 'write', 'delete']);
Gotcha: Confirmation
if (confirm('Do you want to proceed?')) {
// ...
}
Tip: Search Prompt
$user = search('Find a user', fn(string $value) => User::where('name', 'like', "%{$value}%")->pluck('name', 'id'));
Gotcha: Progress Bar
withProgressBar(User::all(), fn($user) => process($user));
Tip: Use route:cache Carefully
php artisan route:cache is fast, but it doesn't work with closure-based routes. Every time you cache routes, Laravel serializes them. If you have Route::redirect() or closure callbacks, the cache breaks. Stick to controller-based routes in production.
Tip: Model APP_KEY Rotation
Rotating APP_KEY invalidates all encrypted data — cookies, encrypted DB columns, and password reset tokens. If you must rotate (e.g., after a leak), plan a migration that re-encrypts existing data with the new key.
Gotcha: Local Scope Leaks
Global scopes defined in booted() apply to ALL queries on that model — including relationships. An innocent User::all() in admin panel might exclude soft-deleted users if a global scope is active.
Senior Insight
Laravel Prompts is one of those packages that makes CLI tools genuinely enjoyable to build and use. I've replaced dozens of one-off Bash scripts with Artisan commands using Prompts — and the team actually uses them now. The key insight: a CLI tool that asks clear questions and shows progress has much higher adoption than one that expects flags and parameters memorized from a README.
Source: Laravel News (https://laravel-news.com/), Freek.dev (https://freek.dev/tags/laravel), Spatie Blog (https://spatie.be/blog)