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 listprints 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.)
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.
#1 Best Overall
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.
Recommended Free Tools
4. Run it
php artisan mail:send 1
Use php artisan help mail:send to confirm that the arguments and options appear as intended.
Rank #3
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.
Rank #4
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.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteClass 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.
Best Value
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::callruns a command from anywhere in your PHP code, such as a route or controller.$this->callruns another command from inside a command.Artisan::queuepushes 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.
Quick Recap
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.

