https://github.com/tomhatzer/nova-business-hours
https://github.com/tomhatzer/nova-business-hours
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tomhatzer/nova-business-hours
- Owner: tomhatzer
- Created: 2021-03-14T19:03:59.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-12-14T01:37:47.000Z (over 3 years ago)
- Last Synced: 2025-10-11T14:07:12.363Z (9 months ago)
- Language: Vue
- Size: 2.26 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Nova Business Hours Field
This package offers a field for Nova to easily manage your business hours.
## Install
```bash
composer require tomhatzer/nova-business-hours
```
## Usage
Add this line to your Nova resource fields array:
```php
NovaBusinessHours::make('Business hours', 'business_hours'),
```
## Compatibility
### Using this package with spatie/open-hours
Create a getter for your business hours field in your model like this:
```php
public function getBusinessHoursAttribute($value)
{
$jsonDecoded = json_decode($value);
return collect($jsonDecoded)->transform(function($day) {
return array_filter(
array_map(function($item) {
if($item->isOpen) {
return substr_replace($item->open, ':', 2, 0) . '-' . substr_replace($item->close, ':', 2, 0);
}
return null;
}, $day)
);
})->all();
}
```
In this case the fields name will be `business_hours`. Customize this according to your database column name.
Afterwards you can use it to fill the `OpeningHours` class with your existing business hours like this:
```php
// Add the use at the top of each file where you want to use the OpeningHours class:
use Spatie\OpeningHours\OpeningHours;
// Get your model instance
$model = Model::find(1);
// Fill the OpeningHours class with your business hours
$openingHours = OpeningHours::create($model->business_hours);
```