What is Artisan?
Artisan is the command-line interface bundled with Laravel. It lives at the project root as theartisan script and provides dozens of commands to help you build and maintain your application.
List all available commands:
If you use Laravel Sail, replace
php artisan with sail artisan. Commands run inside the Docker container.Tinker (REPL)
Laravel Tinker is an interactive REPL that lets you interact with your application directly from the terminal—query Eloquent models, dispatch jobs, fire events, and more.Writing commands
Generating a command
Usemake:command to scaffold a new command class in app/Console/Commands:
Command structure
In Laravel 13, define the command signature and description with PHP attributes. Thehandle() method contains the logic:
You can also use the classic
$signature and $description properties instead of attributes—both work in Laravel 13.Exit codes
A command exits with0 (success) by default. Return an integer from handle() to set a custom exit code:
fail() to immediately terminate with exit code 1:
Closure commands
Define lightweight commands directly inroutes/console.php without a full class:
Defining input
Arguments and options
Define arguments and options in the$signature string (or #[Signature] attribute):
Retrieving input
input() — typed accessors
The input() method lets you retrieve command arguments and options through the same typed accessors available on HTTP requests.
Interacting with the user
Output methods
Prompting for input
Progress bars
Display progress for long-running operations:Practical example: data import command
1
Generate the command
2
Implement the command
3
Run the command
Scheduling commands
Register commands inroutes/console.php to run them on a schedule. See the Task scheduling guide for details.
Testing commands
Use theartisan() testing helper to simulate running a command: