0
私は自分自身でLaravelコマンドを教えて、後で私はそれらをスケジューリングに使用します。これは私のカーネルファイルです:コンソールからlaravel artisanコマンドを呼び出す
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
'App\Console\Commands\FooCommand',
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
$schedule->command('App\Console\Commands\FooCommand')->hourly();
}
/**
* Register the Closure based commands for the application.
*
* @return void
*/
protected function commands()
{
require base_path('routes/console.php');
}
}
そして、これは\アプリケーション\コンソール\コマンド内のコマンドファイル
namespace App\Console\Commands;
use Illuminate\Console\Command;
class FooCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = '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 handle()
{
//
}
public function fire()
{
$this->info('Test has fired.');
}
}
である私はFooCommandコマンドをテストしたいです。どのようにしてシェルからこのコマンドを呼び出して、結果が "テストが起動しました"か?
感謝を。 "SecondCommand"のような別のコマンドファイルを追加するとどうなりますか?私はそれをどのように呼びますか? – user7432810
'schedule:run'コマンドは、' schedule'関数で登録されたすべてのコマンドを実行します。 'schedule'コマンドの中に' $ schedule-> command( 'command:name') - > hourly();のような新しいコマンドを追加するだけです。 – MarcosRJJunior