Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make laravel schedule command last day of month at time

Tags:

laravel

I'm trying to run a command the last day of the month at 06:00, I tried doing this

$schedule->command('crawl')->when(function () {
return \Carbon\Carbon::now()->endOfMonth()->isToday();
})->at('06:00');

It does run on the last day, but the "at" does not work. Any idea how I can get it to work?

like image 993
Klaus Avatar asked Jan 01 '23 22:01

Klaus


1 Answers

I'd simply use the monthlyOn() schedule method, because it gives you the opportunity to point at a given day of the month and a daytime to execute the command. Using php's date() function to retrieve the count of days in a month, this becomes an enjoyable task:

->monthlyOn(date('t'), '6:00');
like image 169
D. Petrov Avatar answered Jan 05 '23 02:01

D. Petrov