This document explains how the Laravel application processes command-line interface (CLI) commands through the Artisan console system. It covers the command execution lifecycle from the artisan
script entry point through command registration, routing, and execution.
For information about HTTP request processing, see HTTP Request Processing. For details about the application bootstrap process that underlies both HTTP and CLI processing, see Application Bootstrap and Lifecycle.
The Laravel application provides CLI access through the artisan
script located in the project root. This script serves as the entry point for all console commands and follows a bootstrap process similar to HTTP requests but optimized for command-line execution.
The artisan
script begins with a PHP shebang and establishes the execution environment:
The script performs these key steps:
LARAVEL_START
constant for performance timing artisan7Illuminate\Foundation\Application
instance artisan14Symfony\Component\Console\Input\ArgvInput
object to parse command-line arguments artisan16$app->handleCommand()
for command processing artisan16Sources: artisan1-18
The bootstrap process loads the same bootstrap/app.php
configuration used for HTTP requests. The artisan
script and public/index.php
both follow identical bootstrap patterns but handle different types of input:
Entry Point | Input Type | Handler Method |
---|---|---|
artisan | Symfony\Component\Console\Input\ArgvInput | $app->handleCommand() |
public/index.php | Illuminate\Http\Request | $app->handleRequest() |
Shared Bootstrap Configuration Bridge
The Application::configure()
method in bootstrap/app.php7 establishes console command routing through the commands
parameter bootstrap/app.php10 which points to routes/console.php
for command registration.
Sources: artisan14-16 public/index.php18-20 bootstrap/app.php7-18
Laravel provides multiple mechanisms for registering console commands, with the most common approach being through the routes/console.php
file for simple commands and dedicated command classes for complex functionality.
Laravel provides command registration through the console routing system configured in bootstrap/app.php
. Commands can be registered using closure-based patterns or dedicated command classes:
Command Registration Architecture
The registration process supports:
Artisan::command()
method for closure-based commands$this->comment()
->purpose()
method for command descriptionsIlluminate\Console\Command
Sources: bootstrap/app.php10
Commands registered through Artisan::command()
execute within a console context that provides:
Feature | Description | Usage in Example |
---|---|---|
$this->comment() | Output styled text to console | Displaying the inspiring quote |
Facade Access | Full access to Laravel services | Inspiring::quote() facade method |
Argument/Option Parsing | Automatic handling of CLI parameters | Inherited from Symfony Console |
The complete command execution flow demonstrates how CLI input is processed through Laravel's console system:
The Illuminate\Foundation\Application
resolves and executes commands through several steps:
Symfony\Component\Console\Input\ArgvInput
parses command-line arguments artisan5-16routes/console.php
bootstrap/app.php10$this->comment()
The $app->handleCommand(new ArgvInput)
method orchestrates this entire process and returns the status code that the artisan
script passes to exit($status)
.
Sources: artisan16-18 bootstrap/app.php10
Laravel distinguishes between built-in framework commands and application-specific custom commands:
Laravel includes numerous built-in commands accessible through the same artisan
entry point:
php artisan migrate
- Database migrationsphp artisan serve
- Development serverphp artisan test
- Test executionphp artisan config:cache
- Configuration cachingCustom commands can be registered through multiple approaches:
Method | File Location | Use Case |
---|---|---|
Artisan::command() | routes/console.php | Simple closure-based commands |
Command Classes | app/Console/Commands/ | Complex commands extending Illuminate\Console\Command |
Service Providers | app/Providers/ | Commands requiring dependency injection |
All commands, whether built-in or custom, are processed through the same $app->handleCommand()
method in the artisan
script.
Sources: artisan16
Console commands utilize Symfony Console's output system through Laravel's console context:
The command execution ultimately returns to the artisan
script, which exits with the appropriate status code to indicate success or failure to the operating system.
Sources: artisan16-18 routes/console.php7
Refresh this wiki