---
title: "Validation and HTTP input — Opening Hours for Laravel | Roundly"
description: "Validate opening-hours payloads with ValidOpeningHours, get every problem under its nested key, and validate programmatically."
url: https://roundly-consulting.com/open-source/docs/opening-hours-for-laravel/validation
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Opening Hours for Laravel](https://roundly-consulting.com/open-source/docs/opening-hours-for-laravel.md)

# Validation and HTTP input

Validate form or API input with the ValidOpeningHours rule, then pass the validated array straight to OpeningHours::sync():

```php
use RoundlyConsulting\OpeningHours\Facades\OpeningHours;
use RoundlyConsulting\OpeningHours\Rules\ValidOpeningHours;
use RoundlyConsulting\OpeningHours\Rules\ValidTimeRange;

public function rules(): array
{
    return [
        'opening_hours' => ['required', 'array', new ValidOpeningHours(requireTimezone: true)],
        'range' => [new ValidTimeRange],
    ];
}

OpeningHours::sync(
    $clinic,
    $request->validated('opening_hours'),
    expectedRevision: $request->filled('revision') ? $request->integer('revision') : null,
);
```

Every problem is reported under its nested key (opening\_hours.schedules.0.week.monday.1) with a translated message: invalid times, empty ranges, overlaps (also across midnight and from Sunday into Monday), two base schedules, ambiguous seasonal windows or exceptions, unknown weekdays, invalid timezones and exceeded limits. new ValidOpeningHours(mergeOverlapping: true) merges overlaps instead of rejecting them — merged ranges no longer match the input positions, so a violation on one names its day (opening\_hours.week.monday) or the exception’s ranges; requireTimezone: true makes the timezone mandatory. ValidTimeRange validates a single range, including the limits.label\_length and limits.meta\_bytes a save applies.

## Programmatic validation

The facade validates without writing; CalendarData::fromArray() throws InvalidOpeningHoursException carrying every violation:

```php
use RoundlyConsulting\OpeningHours\DataTransferObjects\CalendarData;
use RoundlyConsulting\OpeningHours\Exceptions\InvalidOpeningHoursException;
use RoundlyConsulting\OpeningHours\Facades\OpeningHours;

$violations = OpeningHours::validate($payload);   // ViolationList, nothing is written
$violations->isEmpty();
$violations->first()?->message();
$violations->toMessageBag('opening_hours');

try {
    $data = CalendarData::fromArray($payload);
} catch (InvalidOpeningHoursException $e) {
    return back()->withErrors($e->violations()->toMessageBag('opening_hours'));
}
```

## Violation codes

Each violation carries a ViolationCode; its message comes from opening-hours::validation.<code>, in English and Slovak: invalid\_structure, invalid\_time, empty\_range, start\_at\_24, overlap, invalid\_date, invalid\_month\_day, window\_inverted, recurrence\_mismatch, yearly\_window\_unbounded, duplicate\_base\_schedule, ambiguous\_schedule\_window, duplicate\_exception, ambiguous\_exception, invalid\_timezone, timezone\_required, invalid\_calendar\_key, unknown\_weekday, invalid\_priority, invalid\_capacity, limit\_exceeded, label\_too\_long, meta\_too\_large, unknown\_id, duplicate\_id and unsupported\_week\_array\_feature.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/opening-hours-for-laravel.md)
