PHP code example of luedtke / laravel-holiday-facade

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

    

luedtke / laravel-holiday-facade example snippets


// config/holiday.php

return [
    'default'        => 'germany',          // active driver
    'default_locale' => env('HOLIDAY_LOCALE', 'en'), // fallback translation locale

    'drivers' => [
        'germany' => [
            'driver'        => 'germany',
            'timezone'      => env('HOLIDAY_TIMEZONE_DE', 'Europe/Berlin'),
            'locale'        => 'de_DE',
            'default_state' => env('HOLIDAY_DEFAULT_STATE_DE', null), // e.g. 'BY'
        ],
        'swedish' => [
            'driver'   => 'swedish',
            'timezone' => env('HOLIDAY_TIMEZONE_SE', 'Europe/Stockholm'),
            'locale'   => 'sv_SE',
        ],
        'finnish' => [
            'driver'   => 'finnish',
            'timezone' => env('HOLIDAY_TIMEZONE_FI', 'Europe/Helsinki'),
            'locale'   => 'fi_FI',
        ],
        'netherlands' => [
            'driver'   => 'netherlands',
            'timezone' => env('HOLIDAY_TIMEZONE_NL', 'Europe/Amsterdam'),
            'locale'   => 'nl_NL',
        ],
    ],

    'custom' => [
        // Repeats every year (MM-DD)
        ['name' => 'Company Day', 'date' => '06-15', 'type' => 'custom'],
        // One-time date
        ['name' => 'Office Closed', 'date' => '2026-12-27', 'type' => 'custom'],
    ],
];

use Laravel\Holiday\Facades\Holiday;

// Is a date a public holiday?
Holiday::isHoliday('2026-12-25');           // true
Holiday::isHoliday('2026-12-24');           // false — Christmas Eve is an observance
Holiday::isHoliday('2026-12-24', strict: false); // true — ay::previous('2026-01-10')->name;      // "Neujahr"

// Next workday
Holiday::nextWorkday('2026-12-24');         // Carbon instance for 2026-12-28

// Get all holidays for a year
Holiday::getHolidays(2026);                 // Collection of Holiday objects

// Get holidays in a date range
Holiday::getHolidaysBetween('2026-04-01', '2026-04-30');

// Count holidays
Holiday::countHolidays(2026);               // int

// Look up a holiday by date
Holiday::getHoliday('2026-12-25');          // Holiday value object

// Check by name
Holiday::isHolidayByName('Neujahr', 2026);  // true

Holiday::driver('swedish')->isHoliday('2026-06-19');   // true — Midsommarafton (observance)
Holiday::driver('finnish')->getHolidays(2026);
Holiday::driver('netherlands')->next('2026-04-20')->name; // "Koningsdag"

// Only holidays that apply to Bavaria (BY)
Holiday::getHolidays(2026, state: 'BY');

// Heilige Drei Könige applies to BY, BW, ST — not to HH
Holiday::isHolidayByName('Heilige Drei Könige', state: 'BY'); // true
Holiday::isHolidayByName('Heilige Drei Könige', state: 'HH'); // false

// Get the list of supported state codes
Holiday::supportedRegions(); // ['BW', 'BY', 'BE', ...]

Holiday::isHoliday('2026-12-24');                    // false — strict by default
Holiday::isHoliday('2026-12-24', strict: false);     // true

Holiday::next('2026-12-23');                         // 2026-12-25 (skips Christmas Eve)
Holiday::next('2026-12-23', strict: false);          // 2026-12-24 (

$holiday = Holiday::next('2026-12-24');

$holiday->name;               // "1. Weihnachtstag" (native — always German for the germany driver)
$holiday->translate('en');    // "Christmas Day"
$holiday->translate('de');    // "1. Weihnachtstag"
$holiday->translate('sv');    // "Juldagen"
$holiday->translate();        // uses app()->getLocale(), falls back to config('holiday.default_locale')

'custom' => [
    // Repeats every year — format: MM-DD
    ['name' => 'Company Day', 'date' => '06-15', 'type' => 'custom'],

    // One-time date — format: YYYY-MM-DD
    ['name' => 'Office Closed', 'date' => '2026-12-27', 'type' => 'custom'],

    // Region-restricted custom holiday
    ['name' => 'Munich Office Day', 'date' => '09-21', 'type' => 'custom', 'states' => ['BY']],
],

$holiday = Holiday::getHoliday('2026-12-25');

$holiday->name;                // "1. Weihnachtstag"
$holiday->date;                // Carbon instance
$holiday->country;             // "germany"
$holiday->type;                // HolidayType::Public
$holiday->states;              // null (nationwide) or ['BY', 'BW', ...]
$holiday->locale;              // "de_DE"
$holiday->key;                 // "christmas_day" (stable translation key)
$holiday->translate('en');     // "Christmas Day"
bash
php artisan vendor:publish --tag=holiday-config
bash
php artisan vendor:publish --tag=holiday-lang
bash
php artisan vendor:publish --tag=holiday-lang
# edit resources/lang/vendor/holiday/en/holidays.php