Smbat Poghosyan
Smbat Poghosyan

Reputation: 809

Task Scheduling on custom day Laravel

I want do this job oly on this days can I use at() with when() ????

$schedule->command('mycommand')->when(function () {
            $day = Carbon::today()->day;
            if($day == 3 || $day == 5 || $day == 7 || $day == 22) {
                return true;
            } else {
                return false;
            }
        })->at('17:00');

Upvotes: 0

Views: 788

Answers (2)

Vincent Decaux
Vincent Decaux

Reputation: 10714

You can use this way :

$schedule->command('mycommand')->monthlyOn(3, '17:00');
$schedule->command('mycommand')->monthlyOn(5, '17:00');
$schedule->command('mycommand')->monthlyOn(7, '17:00');
$schedule->command('mycommand')->monthlyOn(22, '17:00');

Or, simpler way, using cron :

$schedule->command('mycommand')->cron('0 17 3,5,7,22 * *');

Upvotes: 4

Salim Djerbouh
Salim Djerbouh

Reputation: 11034

You can duplicate multiple monthly runs on specific days

$schedule->command('mycommand')->monthlyOn(3, '17:00');
$schedule->command('mycommand')->monthlyOn(5, '17:00');
$schedule->command('mycommand')->monthlyOn(7, '17:00');
$schedule->command('mycommand')->monthlyOn(22, '17:00');

Hope this helps

Upvotes: 2

Related Questions