Skip to main content

Laravel Custom Artisan Commands

Build professional Artisan commands with argument parsing, interactive prompts, progress bars, output formatting, and scheduled execution.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Create a suite of 5 custom Artisan commands for a subscription billing platform application. The commands handle subscription lifecycle management, invoice generation, payment reconciliation, and reporting and will be run by developers via CLI and the scheduler in production. Use Laravel 11. Build these commands following best practices: 1) Create the primary command billing:process-renewals: define the signature with required arguments, optional arguments with defaults, and 6 options (flags and value options). Write a detailed description and help text. Implement handle() with: input validation, a confirmation prompt for destructive operations using $this->confirm(), and exit codes (0 success, 1 failure, 2 invalid input). 2) Implement rich output formatting: use $this->info(), $this->warn(), $this->error() for status messages, $this->table() for tabular data with ID, Customer, Plan, Amount, Status, Processed At columns, $this->newLine() for spacing, and the Laravel Prompts library for select (plan filter), multiselect (status filter), and text (date range). Add --quiet flag support that suppresses non-essential output. 3) Build long-running command support: add a progress bar for processing 10,000 records, implement signal handling (SIGINT/SIGTERM) for graceful shutdown that completes the current item and reports progress, and add --dry-run flag that shows what would happen without making changes. 4) Create a command that interacts with external services: connect to Stripe API for payment processing, implement retry logic with 3 attempts and exponential backoff, handle timeouts of 30 seconds, and log all API interactions. Add --verbose (-v, -vv, -vvv) output levels that show progressively more detail. 5) Implement command dependencies: create a parent command that orchestrates 3 sub-commands in sequence, passes shared context between them, handles partial failures (continue vs. abort), and generates a summary report at the end. 6) Add scheduling: register commands in routes/console.php with appropriate schedules (renewals: daily at 6am, invoices: hourly, reconciliation: daily at midnight, reports: weekly Monday 8am), configure overlap prevention with withoutOverlapping(), add onSuccess/onFailure callbacks that notify via Slack webhook to #billing-ops channel, and implement maintenance mode awareness. 7) Write tests for each command using Artisan::call() and assertExitCode(): test argument parsing, test output contains expected strings, test database state changes, and mock external service calls.

What this prompt does

This prompt makes the AI create a suite of [command_count] custom Artisan commands for a [app_description], handling [command_purposes] and run by [operators] on Laravel [laravel_version]. It builds the primary command [primary_command] with a full signature, [option_count] options, validation, a confirmation prompt for destructive actions, and proper exit codes. Naming the operators and purposes is what steers the AI toward safe, operator-grade tooling rather than throwaway scripts.

The structure works because production CLI tools live or die on the details here. Rich output uses $this->table() with [table_columns] and Laravel Prompts for [interactive_prompts]; long-running support adds a progress bar over [batch_size] records, signal handling, and a --dry-run flag; external-service commands add retries with backoff and [timeout_seconds] timeouts; a parent command orchestrates [sub_command_count] sub-commands; scheduling uses [schedules] with overlap prevention and [notification_method] callbacks; and every command gets Artisan::call() tests. The --verbose levels (-v, -vv, -vvv) on external-service commands surface progressively more detail when an API call misbehaves, and the --quiet flag suppresses non-essential output for scheduled runs. Because you name [operators] and [command_purposes], the AI leans toward operator-grade safeguards — exit codes (0 success, 1 failure, 2 invalid input), input validation, and maintenance-mode awareness — instead of scripts that assume a developer is watching every run.

When to use it

  • You write operational commands for billing, data fixes, or reporting
  • You need destructive commands with confirmation prompts and a dry-run mode
  • You run long batch jobs and want progress bars plus graceful shutdown on SIGINT/SIGTERM
  • You call external APIs from a command and need retries with exponential backoff
  • You want a parent command that orchestrates sub-commands and reports a summary
  • You schedule commands and need overlap prevention and success/failure notifications

Example output

The AI returns Artisan command classes starting with [primary_command]: a defined signature with arguments and [option_count] options, a handle() method with validation, confirmation, and exit codes, table output over [table_columns], Laravel Prompts for [interactive_prompts], progress-bar and signal handling for [batch_size] records with --dry-run, an external-service command with retry and timeout logic, a parent command orchestrating [sub_command_count] sub-commands, scheduling in routes/console.php with overlap prevention, and Artisan::call() tests asserting exit codes and output.

Pro tips

  • Always add --dry-run to anything destructive; previewing changes is the cheapest safety net you can build
  • Wire signal handling so SIGINT finishes the current item and reports progress instead of corrupting a batch
  • Keep [table_columns] tight and meaningful — readable output is what makes a command safe to hand to [operators]
  • Set [retry_count] with backoff for external calls so a transient blip does not fail the whole run
  • Use withoutOverlapping() on every scheduled command so a slow run never stacks on the next tick
  • Cover each command with Artisan::call() and assertExitCode() so a refactor cannot silently break ops

Frequently Asked Questions

How do I make a destructive command safe to run?
The prompt adds a confirmation prompt via `$this->confirm()` for destructive operations plus a `--dry-run` flag that shows what would happen without making changes. Together they let operators preview the impact before committing, which is the main guard against accidental data loss.
Does it handle graceful shutdown of long-running commands?
Yes. It implements SIGINT/SIGTERM signal handling so the command finishes the current item and reports progress before exiting, rather than leaving a `[batch_size]` job half-done. A progress bar tracks how far processing got.
How are external API failures handled inside a command?
The external-service command adds retry logic with `[retry_count]` attempts and exponential backoff, a `[timeout_seconds]` timeout, and logging of all API interactions. Verbosity flags (-v, -vv, -vvv) let you surface more detail when debugging a failure.
Can these commands be tested without running them for real?
Yes. Each command is tested with Artisan::call() and assertExitCode(), asserting argument parsing, expected output strings, and database state changes, while external service calls are mocked. That keeps ops tooling covered so a refactor cannot break it silently.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Laravel & PHP Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support