
ショコラ
Laravel コマンドを作成するには?
「./artisan {コマンド}」でキメマス。
コマンドは例えば「cache:clear」のようにコロンで区切られた値。
コマンドの一覧は「./artisan list」で表示できます。

もっさん先輩
コマンドを実行する。
./artisan {コマンド}
コマンド一覧を表示する。
./artisan list
手順
Laravel でコマンドを作成する手順。
- コマンドディレクトリを作成します。
mkdir app/Console/Commands
- コマンドディレクトリに移動します。
cd app/Console/Commands
- コマンドを作成します。
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class Hello extends Command
{
protected $signature = 'hello {name}';
protected $description = 'エコーします。';
public function handle()
{
echo 'Hello,'.$this->argument('name'),PHP_EOL;
}
}
- コマンドを確認します。
./artisan list
- コマンドを実行します。
./artisan hello "Answorz!"
# ./artisan hello "Answorz!"
Hello,Answorz!
以上