Skip to main content

Laravel Custom Artisan Commands

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

Füllen Sie die Platzhalter aus

Edit the values, then copy your finished prompt.

Ihr Prompt
prompt.txt

                                

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.

Mehr in Laravel & PHP Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

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

[email protected]

✓ 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