tomhatzer / nova-business-hours
Business hours field for Laravel Nova.
v0.1.1
2021-03-15 21:46 UTC
Requires
- php: >=7.4.0
- dev-main
- v0.1.1
- v0.1.0
- dev-dependabot/npm_and_yarn/express-4.18.2
- dev-dependabot/npm_and_yarn/qs-6.5.3
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/loader-utils-1.4.2
- dev-dependabot/npm_and_yarn/moment-2.29.4
- dev-dependabot/npm_and_yarn/async-2.6.4
- dev-dependabot/npm_and_yarn/minimist-1.2.6
- dev-dependabot/npm_and_yarn/url-parse-1.5.10
- dev-dependabot/npm_and_yarn/i-0.3.7
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/dns-packet-1.3.4
- dev-dependabot/npm_and_yarn/hosted-git-info-2.8.9
This package is auto-updated.
Last update: 2024-10-14 05:38:23 UTC
README
This package offers a field for Nova to easily manage your business hours.
Install
composer require tomhatzer/nova-business-hours
Usage
Add this line to your Nova resource fields array:
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:
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:
// 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);