Command¶
Create a new command¶
php artisan make:command CommandName
This will generates a CommandName.php
at app/Console/Commands/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
API¶
Warning
The description of the command need to insert spaces before and after the colon. e.g. {arg : description}'
Arguments¶
-
Define
1
protected $signature = 'test:command {arg1 : All jobs}';
-
Access
1 2 3
$this->argument("arg1"); // arg1 $this->arguements(); // A list of arguments
Options¶
- Define
1 |
|
- Access
1 2 3 4 5 |
|
Advanced arguements or options¶
protected $signature = 'test:command {--Q|queue} ';
// Input array
protected $signature = 'test:command {input=*}'; // for Arguemtns
protected $signature = 'email:send {user} {--id=*}'; // for Options
Output¶
- Write outputs with level
$this->line() $this->info() $this->comment() $this->question() $this->error()