diff --git a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php index 8faf51b72726..c24a39a94a0d 100644 --- a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php +++ b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php @@ -568,6 +568,21 @@ public function lastDayOfMonth($time = '0:0') return $this->spliceIntoPosition(3, Carbon::now()->endOfMonth()->day); } + /** + * Schedule the event to run on specific days of the month. + * + * @param array>|int<1, 31> ...$days + * @return $this + */ + public function daysOfMonth(...$days) + { + $days = count($days) === 1 && is_array($days[0]) ? $days[0] : $days; + + $this->dailyAt('0:0'); + + return $this->spliceIntoPosition(3, implode(',', $days)); + } + /** * Schedule the event to run quarterly. * diff --git a/tests/Console/Scheduling/EventTest.php b/tests/Console/Scheduling/EventTest.php index ae0a5339d7ef..4717a6ec2d35 100644 --- a/tests/Console/Scheduling/EventTest.php +++ b/tests/Console/Scheduling/EventTest.php @@ -104,4 +104,16 @@ public function testCustomMutexName() $this->assertSame('fancy-command-description', $event->mutexName()); } + + public function testDaysOfMonthMethod() + { + $event = new Event(m::mock(EventMutex::class), 'php -i'); + + $event->daysOfMonth(1, 15); + $this->assertSame('0 0 1,15 * *', $event->getExpression()); + + $event = new Event(m::mock(EventMutex::class), 'php -i'); + $event->daysOfMonth([1, 10, 20, 30]); + $this->assertSame('0 0 1,10,20,30 * *', $event->getExpression()); + } }