> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devdeia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Usage

> The HasBusinessHours trait, and the form field, table column, and infolist entry.

## Add the trait to your model

`HasBusinessHours` provides a `morphOne` relationship to `BusinessHours`, an accessor to get an `OpeningHours` instance, and helper methods:

```php theme={null}
use Andreia\FilamentBusinessHours\Concerns\HasBusinessHours;

class Business extends Model
{
    use HasBusinessHours;
}
```

```php theme={null}
$model = Company::find($companyId);

$model->isOpen();                       // Check if currently open
$model->nextOpen();                     // Get next opening time
$model->currentOpenRange();             // Get current open range
$model->isOpen(now()->addDays(2));      // Check a specific date/time
```

Every method from [Spatie's Opening Hours](https://github.com/spatie/opening-hours) is also available for querying and formatting.

## Form field

```php theme={null}
use Andreia\FilamentBusinessHours\Forms\Components\BusinessHoursField;

BusinessHoursField::make('businessHours')
    ->allowExceptions()
```

Any form layout can wrap it:

```php theme={null}
use Andreia\FilamentBusinessHours\Forms\Components\BusinessHoursField;
use Filament\Forms;

Forms\Components\Section::make('Business Hours')
    ->description('Control the availability of hours on each weekday')
    ->icon('heroicon-o-clock')
    ->schema([
        BusinessHoursField::make('businessHours')
            ->allowExceptions(),
    ]),
```

### Exceptions

`->allowExceptions()` adds a "Set up" button that opens a modal for holidays, special hours, and closures. They're saved Spatie-style in an `exceptions` column:

```php theme={null}
'exceptions' => [
    '2025-11-11' => ['09:00-12:00'],
    '2025-07-04' => [],                  // closed all day
    '01-01'      => [],                  // recurring annually
    '12-25'      => ['09:00-12:00'],     // recurring annually
    '12-25 to 12-25' => [
        'hours' => [],
        'data' => 'Holidays',
    ],
    '2025-06-25 to 2025-07-01' => [
        'hours' => [],
        'data' => 'Closed for works',
    ],
]
```

## Table column

```php theme={null}
use Andreia\FilamentBusinessHours\Tables\Columns\BusinessHoursColumn;

// businessHours is the name of the relationship
BusinessHoursColumn::make('businessHours')
```

## Infolist entry

```php theme={null}
use Andreia\FilamentBusinessHours\Infolists\Components\BusinessHoursEntry;

// businessHours is the name of the relationship
BusinessHoursEntry::make('businessHours')
```

Any infolist layout can wrap it:

```php theme={null}
use Andreia\FilamentBusinessHours\Infolists\Components\BusinessHoursEntry;
use Filament\Infolists;

Infolists\Components\Section::make('Business Hours')
    ->description('Control the availability of hours on each weekday')
    ->icon('heroicon-o-clock')
    ->schema([
        BusinessHoursEntry::make('businessHours')
            ->hiddenLabel()
            ->columnSpanFull(),
    ]),
```
