'integer', 'server_id' => 'integer', 'is_active' => 'boolean', 'is_processing' => 'boolean', 'only_when_online' => 'boolean', ]; /** * Columns to mutate to a date. */ protected $dates = [ 'last_run_at', 'next_run_at', ]; protected $attributes = [ 'name' => null, 'cron_day_of_week' => '*', 'cron_month' => '*', 'cron_day_of_month' => '*', 'cron_hour' => '*', 'cron_minute' => '*', 'is_active' => true, 'is_processing' => false, 'only_when_online' => false, ]; public static array $validationRules = [ 'server_id' => 'required|exists:servers,id', 'name' => 'required|string|max:191', 'cron_day_of_week' => 'required|string', 'cron_month' => 'required|string', 'cron_day_of_month' => 'required|string', 'cron_hour' => 'required|string', 'cron_minute' => 'required|string', 'is_active' => 'boolean', 'is_processing' => 'boolean', 'only_when_online' => 'boolean', 'last_run_at' => 'nullable|date', 'next_run_at' => 'nullable|date', ]; /** * {@inheritDoc} */ public function getRouteKeyName(): string { return $this->getKeyName(); } /** * Returns the schedule's execution crontab entry as a string. * * @throws \Exception */ public function getNextRunDate(): CarbonImmutable { $formatted = sprintf('%s %s %s %s %s', $this->cron_minute, $this->cron_hour, $this->cron_day_of_month, $this->cron_month, $this->cron_day_of_week); return CarbonImmutable::createFromTimestamp( (new CronExpression($formatted))->getNextRunDate()->getTimestamp() ); } /** * Return a hashid encoded string to represent the ID of the schedule. */ public function hashid(): Attribute { return Attribute::make( get: fn () => Container::getInstance()->make(HashidsInterface::class)->encode($this->id), ); } /** * Return tasks belonging to a schedule. */ public function tasks(): HasMany { return $this->hasMany(Task::class); } /** * Return the server model that a schedule belongs to. */ public function server(): BelongsTo { return $this->belongsTo(Server::class); } }