目的
- laravelにて時間を指定してバッチを実行する方法をメモ的にまとめる
方法
- 下記ファイルを開く。
アプリ名ディレクトリ/app/Console/Kernel.php
-
Kernelクラスのschedule()メソッドに時間で実行したいバッチの情報を記載する。
アプリ名ディレクトリ/app/Console/Kernel.php/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { $schedule->command('command:バッチ名')->実行タイミングの指定; }
-
例えば毎日12:00に実行指定ほしいバッチを登録する場合下記のように記載する。
アプリ名ディレクトリ/app/Console/Kernel.php/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { $schedule->command('command:バッチ名')->dailyAt('12:00'); }