PHP code example of jeffersongoncalves / laravel-open-hours

1. Go to this page and download the library: Download jeffersongoncalves/laravel-open-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/ */

    

jeffersongoncalves / laravel-open-hours example snippets


use JeffersonGoncalves\OpenHours\OpenHours;

$hours = app(OpenHours::class);

$hours->isOpen();               // now, in the schedule's timezone
$hours->isOpen($dateTime);
$hours->nextOpen();             // CarbonImmutable|null (null = never opens)
$hours->nextClose();            // CarbonImmutable|null (null = open 24/7)
$hours->statusText();           // "Open now · closes at 18:00", "Closed · opens Monday at 09:00"
$hours->schedule();             // the full Spatie\OpeningHours\OpeningHours instance

use JeffersonGoncalves\OpenHours\Settings\OpenHoursSettings;

$settings = app(OpenHoursSettings::class);
$settings->timezone = 'America/Sao_Paulo'; // '' = app.timezone
$settings->week['saturday'] = ['09:00-13:00'];
$settings->exceptions = [
    ['date' => '12-25', 'hours' => [], 'note' => 'Christmas'],         // every year, closed
    ['date' => '2026-12-24', 'hours' => ['09:00-12:00'], 'note' => null], // one-off, short day
];
$settings->save();
bash
php artisan vendor:publish --tag=open-hours-config