I am using laravel 5.2 commands via scheduler, i can call the command by following code:
$schedule->command('command:name')
->dailyAt('08:55');
but now i want to call above command daily at six different times i.e. 8:45, 9:15, 9:45,10:15 etc
$schedule->command('command:name')
->when(function(){return true;});
Above code, with when function, isn't working somehow, can someone suggest best practices of laravel.
Why not just define 4 tasks, it's simple and readable:
$schedule->command('command:name')->dailyAt('08:55');
$schedule->command('command:name')->dailyAt('09:15');
$schedule->command('command:name')->dailyAt('09:45');
$schedule->command('command:name')->dailyAt('10:15');
Also, you can put it in a loop:
foreach (['08:45', '09:15', '09:45', '10:15'] as $time) {
$schedule->command('command:name')->dailyAt($time);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With