Issue
I want to run a cron only on last Monday of the month using Laravel's Cron API. I have checked this:
https://laravel.com/docs/5.3/scheduling
I don't get any solution there.
At most I can:
$schedule->command(Commands\PerformerReminder::class)->monthly()->mondays();
But I think it will run the cron on each Monday of the month, not just on the last Monday.
If that is not possible using Laravel's cron API, them I'm fine with using regular cron options.
I think that will be like this:
$schedule->command(Commands\PerformerReminder::class)->cron('* * * * *);
I don't know what will be the value inside cron() function.
Any help would be appriciated.
Thanks,
Parth Vora
Solution
I got that working with this:
App/Console/Kernal.php:
protected function schedule(Schedule $schedule)
{
$schedule
->command(Commands\PerformerReminder::class)
->when(fn() => Carbon::parse('last monday of this month')->isToday());
}
Answered By - Parth Vora Answer Checked By - David Goodson (WPSolving Volunteer)