Skip to main content

Business Hours

Business hours schedules and their days, time ranges and exceptions.

BusinessHoursSchedule​

A business hours schedule: weekly open hours, date exceptions, and where calls go when open and when closed.

Table: business_hours_schedules
Model: App\Models\BusinessHoursSchedule
Tenant scoped: yes (OrganizationScope)
Traits: HasUnprovisionedState, SoftDeletes

ColumnTypeNullableDefaultDescription
idbigint unsignedNoautoPrimary key
organization_idbigint unsignedNo-Tenant. Foreign key to organizations, on delete cascade
namevarchar(255)No-Schedule name
statusenumNoactiveActive or inactive. An inactive schedule is never open. Values: active, inactive (cast to BusinessHoursStatus)
timezonevarchar(50)NoUTCTime zone the hours are evaluated in
open_hours_actionvarchar(255)No-Open-hours target, JSON such as {"target_id": "ext-12"}
open_hours_action_typeenumNoextensionOpen-hours destination kind. Values: extension, ring_group, conference_room, ivr_menu, ai_assistant, ai_load_balancer, unavailable, call_queue (cast to BusinessHoursActionType)
closed_hours_actionvarchar(255)No-Closed-hours target, same format
closed_hours_action_typeenumNoextensionClosed-hours destination kind. Values: extension, ring_group, conference_room, ivr_menu, ai_assistant, ai_load_balancer, unavailable, call_queue (cast to BusinessHoursActionType)
created_attimestampYesnull
updated_attimestampYesnull
deleted_attimestampYesnullSoft-delete timestamp

Indexes

  • bh_schedules_deleted_idx: deleted_at
  • bh_schedules_org_status_idx: organization_id, status

Casts: open_hours_action (json), closed_hours_action (json)

Relationships

$businessHoursSchedule->organization() → Organization (organization_id) [BelongsTo]
$businessHoursSchedule->scheduleDays() → BusinessHoursScheduleDay (business_hours_schedule_id) [HasMany]
$businessHoursSchedule->exceptions() → BusinessHoursException (business_hours_schedule_id) [HasMany]

Scopes: forOrganization(), withStatus(), search(), active(), unprovisioned()
Methods: isActive(), isInactive(), getCurrentStatusAttribute(), isCurrentlyOpen(), getExceptionForDate(), getCurrentRouting(), parseTargetId() (static), isValidTargetId() (static), getOpenHoursActionType(), getClosedHoursActionType(), getOpenHoursTargetId(), getClosedHoursTargetId(), getCurrentRoutingType(), getCurrentRoutingTargetId()

isCurrentlyOpen() converts the time to the schedule's timezone, checks the exception for that date first, then the enabled day's time ranges (start inclusive, end exclusive). getCurrentRouting() returns the open or closed action. Target IDs use the prefixes ext-, rg-, conf-, ivr- and queue- (parseTargetId()). unprovisioned() is true when either action type is unavailable.

BusinessHoursScheduleDay​

One weekday of a schedule.

Table: business_hours_schedule_days
Model: App\Models\BusinessHoursScheduleDay
Tenant scoped: no

ColumnTypeNullableDefaultDescription
idbigint unsignedNoautoPrimary key
business_hours_schedule_idbigint unsignedNo-Schedule. Foreign key to business_hours_schedules, on delete cascade
day_of_weekenumNo-Weekday. Values: monday, tuesday, wednesday, thursday, friday, saturday, sunday (cast to DayOfWeek)
enabledbooleanNofalseOpen on this day
created_attimestampYesnull
updated_attimestampYesnull

Indexes

  • bh_schedule_days_schedule_idx: business_hours_schedule_id
  • bh_schedule_days_unique (unique): business_hours_schedule_id, day_of_week

Relationships

$businessHoursScheduleDay->schedule() → BusinessHoursSchedule (business_hours_schedule_id) [BelongsTo]
$businessHoursScheduleDay->timeRanges() → BusinessHoursTimeRange (business_hours_schedule_day_id) [HasMany]

Methods: isEnabled()

BusinessHoursTimeRange​

An open period on a weekday.

Table: business_hours_time_ranges
Model: App\Models\BusinessHoursTimeRange
Tenant scoped: no

ColumnTypeNullableDefaultDescription
idbigint unsignedNoautoPrimary key
business_hours_schedule_day_idbigint unsignedNo-Weekday row. Foreign key to business_hours_schedule_days, on delete cascade
start_timetimeNo-Opens at
end_timetimeNo-Closes at
created_attimestampYesnull
updated_attimestampYesnull

Indexes

  • bh_time_ranges_day_idx: business_hours_schedule_day_id

Relationships

$businessHoursTimeRange->scheduleDay() → BusinessHoursScheduleDay (business_hours_schedule_day_id) [BelongsTo]

Methods: includes()

BusinessHoursException​

A date that overrides the weekly hours (a holiday or special hours).

Table: business_hours_exceptions
Model: App\Models\BusinessHoursException
Tenant scoped: no

ColumnTypeNullableDefaultDescription
idbigint unsignedNoautoPrimary key
business_hours_schedule_idbigint unsignedNo-Schedule. Foreign key to business_hours_schedules, on delete cascade
datedateNo-Date
namevarchar(255)No-Label
typeenumNoclosedClosed all day, or special hours. Values: closed, special_hours (cast to BusinessHoursExceptionType)
created_attimestampYesnull
updated_attimestampYesnull

Indexes

  • bh_exceptions_date_idx: date
  • bh_exceptions_schedule_idx: business_hours_schedule_id

Casts: date (date)

Relationships

$businessHoursException->schedule() → BusinessHoursSchedule (business_hours_schedule_id) [BelongsTo]
$businessHoursException->timeRanges() → BusinessHoursExceptionTimeRange (business_hours_exception_id) [HasMany]

Methods: isClosed(), isSpecialHours(), isOpen()

BusinessHoursExceptionTimeRange​

An open period on a special-hours exception date.

Table: business_hours_exception_time_ranges
Model: App\Models\BusinessHoursExceptionTimeRange
Tenant scoped: no

ColumnTypeNullableDefaultDescription
idbigint unsignedNoautoPrimary key
business_hours_exception_idbigint unsignedNo-Exception. Foreign key to business_hours_exceptions, on delete cascade
start_timetimeNo-Opens at
end_timetimeNo-Closes at
created_attimestampYesnull
updated_attimestampYesnull

Indexes

  • bh_exception_time_ranges_idx: business_hours_exception_id

Relationships

$businessHoursExceptionTimeRange->exception() → BusinessHoursException (business_hours_exception_id) [BelongsTo]

Methods: includes()

BusinessHours (legacy)​

Legacy model on the same business_hours_schedules table. Its $fillable and casts name columns that no longer exist (schedules, holidays, open_hours_routing, closed_hours_routing). The only current use is the IVR request, which checks that a business_hours destination ID exists in the organization. Use BusinessHoursSchedule.

Table: business_hours_schedules
Model: App\Models\BusinessHours
Tenant scoped: yes (OrganizationScope)