How can I assign a laravel task on a specific day of the month?

Now, after reading the docs , I don’t see a direct function for this, but I see the option of using monthly() in combination with the when() method, so I thought if I could do this, maybe:

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

But now I'm afraid that this will not work, because, as far as I see, he will try to limit when() only once a month (maybe not on the date I want it), and then when he skips this month . At least this is what I guess from reading the source of laravel.

So I'm lost, how can I do this?

+5
source share
2 answers

The easiest way is to use the cron method, so in your case

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

This says to run at midnight on the 23rd day of the month.

+7
source

We can also use the default function specified in the laravel schedule

public function frequency(\Illuminate\Console\Scheduling\Event $event){ $event->monthlyOn(24, '17:00'); }

monthlyOn (date, 'time');

This planner will run on the 24th of each month at 5pm.

0
source

Source: https://habr.com/ru/post/1241006/


All Articles