Knowledgebase

Writing Artisan Commands Print

  • phplaravel, cron, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Your own command-line tools.

WHAT THEY ARE FOR

Maintenance tasks Data imports and exports One-off operations Scheduled work

WHY A COMMAND RATHER THAN A SCRIPT

It runs within the application, with access to models, configuration and services.

WHAT TO DEFINE

A name, a description, and any arguments and options.

WHAT TO PROVIDE

Clear output describing what is happening A confirmation prompt for anything destructive A mode that reports without acting

WHY THAT LAST ONE

It allows verification before committing.

WHAT TO RETURN

A meaningful exit status, so failures are detectable.

WHAT TO LOG

That it ran, what it did, and any failure.

WHAT TO BUILD IN

Safety for repeated runs Bounds on how much a single run may affect

WHAT TO BE CAREFUL WITH

Memory, when processing many records.

WHAT TO USE

Chunked processing, rather than loading everything.

WHAT TO TEST

The command, including its failure paths.

WHAT TO SCHEDULE

Anything recurring, through the scheduler rather than separate cron entries.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot