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?
For example, you may schedule a command to run weekly on Monday: // Run once per week on Monday at 1 PM... })->weekly()->mondays()->at('13:00'); // Run hourly from 8 AM to 5 PM on weekdays...
Scheduling artisan commands Laravel has multiple methods of implementing cron jobs, and so far we've seen how to use closures to schedule these tasks. The other method is the use of artisan commands to manage tasks in an application. Laravel provides an interactive command-line tool to create commands at our disposal.
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.
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