LoginSignup
7
6

More than 5 years have passed since last update.

artisanコマンドを引数つきで作ってみる

Posted at

日本語の記事がなかったのでたいしたことないけどメモってみる

参考記事
http://blog.e2info.com/2013/08/09/laravel_artisan/

とりあえずコマンド作成

php artisan command:make HelloCommand

上記コマンドで
app/commands/以下にHelloCommand.phpが作成される。

引数を渡すときはHelloCommand.phpのなかのgetArguments関数をいじる。

protected function getArguments()
{
    return array(
          array('example', InputArgument::REQUIRED, 'An example argument.'),
      );
}

return するarrayの中に入れるarrayがひとつの引数の情報っぽい。
左から

  • 引数の名前
  • 必須かどうか
  • 引数の説明

となる。

複数引数を持たせたいときは

return array(
          array('example', InputArgument::REQUIRED, 'An example argument.'),
          array('example2', InputArgument::REQUIRED, 'An example2 argument.'),
      );

という感じで追加していく。

上記を実行するコマンドは

php artisan command:hello argument1 argument2

こんな感じ。

終わり。

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6