Skip to content

Conversation

@yousefkadah
Copy link
Contributor

Problem

Currently, Laravel only provides limited options for scheduling tasks on specific days of the month:

  • monthlyOn() - runs on a single day
  • twiceMonthly() - runs on exactly two days
  • lastDayOfMonth() - runs on the last day

There's no built-in way to schedule tasks on multiple arbitrary days of the month (e.g., 1st, 10th, 15th, 20th).

Current Workaround:

// Developers must manually specify cron expression
$schedule->command('generate-reports')
    ->cron('0 0 1,10,20 * *'); // Hard to read and error-prone

Solution

Add a daysOfMonth() method that allows scheduling tasks to run on multiple specific days of the month with a clean, intuitive API.

New API:

// Variadic syntax
$schedule->command('generate-reports')
    ->daysOfMonth(1, 10, 20);

// Array syntax
$schedule->command('generate-reports')
    ->daysOfMonth([1, 10, 20]);

Implementation

Added daysOfMonth() method to the ManagesFrequencies trait that accepts multiple day values and builds the appropriate cron expression:

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));
}

Cron Expression: 0 0 1,10,20 * * (midnight on days 1, 10, and 20)


Use Cases

Payroll Processing (Multiple Payment Dates)

$schedule->command('process-payroll')
    ->daysOfMonth(1, 15) // 1st and 15th of each month
    ->timezone('America/New_York');

Weekly Reports on Specific Dates

$schedule->command('generate-weekly-report')
    ->daysOfMonth(7, 14, 21, 28) // Every week approximately
    ->at('09:00');

Quarterly Maintenance Tasks

$schedule->command('quarterly-cleanup')
    ->daysOfMonth(1, 10, 20, 30) // Spread throughout month
    ->sendOutputTo('/var/log/cleanup.log');

Mid-Month and End-Month Billing

$schedule->command('generate-invoices')
    ->daysOfMonth(15, 30) // Mid-month and end of month
    ->emailOutputOnFailure('[email protected]');

- Allows scheduling tasks to run on multiple specific days of the month
- Supports both array and variadic syntax: daysOfMonth(1, 15) or daysOfMonth([1, 15])
- Useful for tasks that need to run on specific dates (payroll, reports, etc.)
- Add comprehensive tests
@taylorotwell taylorotwell merged commit 2303c5e into laravel:12.x Nov 19, 2025
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants