laravel/framework · error · RuntimeException

Invoke an attribute method such as Schedule::daily() before

Error message

Invoke an attribute method such as Schedule::daily() before defining a schedule group.

What it means

Thrown by Schedule::group() (src/Illuminate/Console/Scheduling/Schedule.php:334) when $this->attributes is null — i.e. group() was called before any attribute method (daily(), hourly(), runInBackground(), etc.) populated pending attributes. Groups apply shared attributes to every event inside, so they must be set first.

Source

Thrown at src/Illuminate/Console/Scheduling/Schedule.php:334

        $this->events[] = $event = new Event($this->eventMutex, $command, $this->timezone);

        $this->mergePendingAttributes($event);

        return $event;
    }

    /**
     * Create new schedule group.
     *
     * @param  \Closure  $events
     * @return void
     *
     * @throws \RuntimeException
     */
    public function group(Closure $events)
    {
        if ($this->attributes === null) {
            throw new RuntimeException('Invoke an attribute method such as Schedule::daily() before defining a schedule group.');
        }

        $this->groupStack[] = $this->attributes;
        $this->attributes = null;

        $events($this);

        array_pop($this->groupStack);
    }

    /**
     * Merge the current group attributes with the given event.
     *
     * @param  \Illuminate\Console\Scheduling\Event  $event
     * @return void
     */
    protected function mergePendingAttributes(Event $event)
    {

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Chain an attribute method before group(): $schedule->daily()->group(fn ($s) => ...).
  2. Move shared constraints (timezone, environments) inside the group via attribute calls on $s.
  3. If no shared attributes are needed, don't use group() — register events directly.

Example fix

// before
$schedule->group(function ($schedule) {
    $schedule->call(fn () => x())->daily();
    $schedule->command('reports:send')->daily();
});

// after
$schedule->daily()->group(function ($schedule) {
    $schedule->call(fn () => x());
    $schedule->command('reports:send');
});
Defensive patterns

Strategy: validation

Validate before calling

// group() requires attributes set first; ensure an attribute method runs first
$schedule->daily()->group(fn ($s) => /* events */);

Type guard

// internal-only: attributes populated by an attribute call
// users guard by always chaining an attribute before group()

Try / catch

try {
    $schedule->group($closure);
} catch (\RuntimeException $e) {
    $schedule->daily()->group($closure); // retry with attribute
}

Prevention

When it happens

Trigger: Writing $schedule->group(function ($schedule) { $schedule->call(...); }); with no prior attribute call like $schedule->daily()->group(...).

Common situations: Adopting the fluent Schedule builder API and forgetting the attribute chain; refactoring that drops the attribute call before group.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/089fc8dec2e49418.json. Report an issue: GitHub.