PHP code example of tomhatzer / nova-business-hours

1. Go to this page and download the library: Download tomhatzer/nova-business-hours library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tomhatzer / nova-business-hours example snippets


NovaBusinessHours::make('Business hours', 'business_hours'),

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();
}

// 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);