コマンドを表すクラスを作成することで、これを手動で追加できます。cli コマンドは次のファイルを生成します。
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class Test extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'command:name';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
//
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('example', InputArgument::REQUIRED, 'An example argument.'),
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
);
}
}
ディレクトリに配置しますcommands
(L4の場合はapp/commands
です)。app/start/artisan.php
次に、カスタム コマンドのバインディングをファイルに追加するだけです。
Artisan::add(new Test);
以上です。サーバーの crontab に触れる必要がない場合、これは理想的なソリューションです。CP からアクセスできる場合は、最も簡単な解決策になります。そのような機能がない場合は、カスタム コマンドを実行するように crontab を設定する方法があります。お役に立てれば。