このページの翻訳:
- 日本語 (ja)
- English (en)
最近の更新
- 2024.01.18 SSL Error in Rails created
- 2024.01.18 RailsでSSLエラー 以前のリビジョンを復元 (2024/01/18 07:06)
- 31 CentOS5 TLS1.2 created
- 2024.04.12 MySQL BIT Field created
最近の更新
$ 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"); }
public function handle()
{
$this->info('info');
$this->line('line');
$this->comment('comment');
$this->question('question');
$this->error('error');
$this->table(
['名前', '年齢'],
[
['Taro', 10],
['Laravel', 5],
]
);
}
$this->call('command:called', ['--path' => 'call']);