Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
FREEDOM251

Freedom251 › Blog › Artisan

Laravel Artisan Commands: How to List Them and Create Your Own Custom Command (Laravel 12.x)

By Freedom251 Team · · 3 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Artisan is Laravel’s command-line interface. To create a custom command, run php artisan make:command SendEmails, set the $signature and $description in the generated class, and put the logic in its handle() method. This guide follows the Laravel 12.x Artisan Console documentation. That page is marked as an older version and points to 13.x, so check the documentation for your installed framework version before relying on paths or APIs shown here.

How do I see which Artisan commands exist?

The artisan script sits in your application root. Two commands cover discovery:

As an Amazon Associate I earn from qualifying purchases.

  • php artisan list prints every available command.
  • php artisan help <command> shows that command’s arguments and options.

If you use Laravel Sail, prefix the call with Sail’s binary: ./vendor/bin/sail artisan list. (Source: Laravel 12.x Artisan guide.)

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I create a custom Artisan command?

1. Generate the class

php artisan make:command SendEmails

In Laravel 12.x this creates a class in app/Console/Commands, creating the directory if it does not exist.

2. Define the signature and description

The generated class has a signature, which is the name plus its expected input, and a description shown in php artisan list. A clear name such as mail:send {user} declares one required argument called user.

3. Write handle()

Laravel runs handle() when the command is called. You can type-hint dependencies there and the service container resolves them. The official example injects a DripEmailer service and uses the user argument to decide who gets mail. The guide’s advice is: “For greater code reuse, it is good practice to keep your console commands light and let them defer to application services to accomplish their tasks.” Treat the command as a thin entry point that reads input and calls your own service classes.

Inside the class, read input with $this->argument('user') and $this->option('queue'). The code samples in the guide are the reference here; check them against your version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Run it

php artisan mail:send 1

Use php artisan help mail:send to confirm that the arguments and options appear as intended.

How do I define arguments and options?

Everything is expressed in the signature string. The 12.x guide documents these forms:

Goal Signature syntax Kind
Required argument {user} Positional
Optional argument {user?} Positional
Argument with default {user=foo} Positional
Boolean switch {--queue} Option, true when passed
Option that takes a value {--queue=} Option, used as --queue=value
Repeated values *, for example {user*} Array input

Arguments are positional and identified by order. Options are named with -- and can be given in any order. The guide also covers shortcuts and descriptions for inputs in the signature. Check the Artisan guide for the exact syntax.

Prompting for missing input

If a required argument is omitted, the command normally fails. Implement the PromptsForMissingInput interface and Laravel asks the user for it interactively.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Class command or closure command?

Class command Closure command
Where Dedicated class, by default in app/Console/Commands Artisan::command(...) in routes/console.php
Dependencies Type-hinted into handle(), as in the guide’s example Defined inline with the closure
Suits Commands that deserve their own file Small, quick commands

The guide presents both as available approaches, not as a ranking.

Where does Laravel look for commands?

Laravel registers commands in app/Console/Commands automatically. Per the guide: “When Artisan boots, all the commands in your application will be resolved by the service container and registered with Artisan.” To load commands from another directory, or to register specific classes, use withCommands in bootstrap/app.php in a Laravel 12.x application.

How do I call a command from code?

  • Artisan::call runs a command from anywhere in your PHP code, such as a route or controller.
  • $this->call runs another command from inside a command.
  • Artisan::queue pushes the command onto the queue. It only works if the queue is configured and a worker is running.

For the full method list on the command class, see the IlluminateConsoleCommand API reference.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

ArtisanCLIcustom commandsLaravelPHP

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.