Ad

How Can I Schedule A Laravel Task On A Specific Day Of The Month?

- 1 answer

Now reading through the docs I don't see a direct function for that, but I do see the option to use the monthly() method combined with a when() method, so I thought, could I do this maybe:

$schedule->command('send:reminders')->monthly()->when(function() {
    return date('d') == '23';
});

But now I'm afraid that won't work, because as far as I can see it will try the when() constraint only once a month (probably not on the date that I want it to) and then when it fails it skips that month. At least that's what I'm guessing from reading the source of laravel.

So then I'm lost, how do I make this happen?

Ad

Answer

The easiest way might be to make use of the cron method so in your case

$schedule->command('send:reminders')->cron('0 0 23 * *');

That is saying run at midnight on the 23rd day of the month.

Ad
source: stackoverflow.com
Ad