このページの翻訳:
- 日本語 (ja)
- English (en)
最近の更新
最近の更新
文書の過去の版を表示しています。
$ php artisan make:command sample/test $ ll app/Console/Commands/sample/test.php -rw-r--r-- 1 matsui users 677 Jan 30 16:01 app/Console/Commands/sample/test.php
app/Console/Commands/sample/test.php
protected $signature = 'command:name'; ↓ protected $signature = 'command:test'; protected $description = 'Command description'; ↓ protected $description = 'てすとコマンド';
app/Console/Kernel.php
protected $commands = [ // ]; ↓ protected $commands = [ Commands\sample\test::class ];
$ php artisan ・ ・ ・ command command:test てすと ・ ・ ・
必須引数
protected $signature = 'command:test {arg}';
任意引数
protected $signature = 'command:test {arg?}';
デフォルト値の指定
protected $signature = 'command:test {arg=argument}';
引数に説明を付ける場合
protected $signature = 'command:test {arg : 引数を指定}';
例:
$ php artisan command:test -h Description: てすとコマンド Usage: command:test <arg> Arguments: arg 引数を指定
public function handle() { $name = $this->argument("name"); $this->info("Hello $name"); }
オプション指定
protected $signature = 'command:test {--dry-run}';
値指定オプション
protected $signature = 'command:test {--dry-run=}';
デフォルト値オプション
protected $signature = 'command:test {--dry-run=1}';
オプションに説明を追加
protected $signature = 'command:test {--dry-run : 実行テスト}';
オプションにショートカット指定
protected $signature = 'command:test {--d|--dry-run : 実行テスト}';
例:
$ php artisan command:test -h Description: てすとコマンド Usage: command:test [options] Options: -d, --dry-run 本番実行
public function handle() { $dry_run = $this->option("dry-run"); $this->info("Option $dry_run"); }