spatie/holidays
Calculate public holidays for supported countries in PHP. Fetch holidays for the current or a specific year using an ISO country code or country class (with region-based holidays). Simple API: Holidays::for(...)->get() returns an array of holiday dates/names.
Holidays::for('us')->get()).Holiday model events or by extending the package’s HolidayRepository (though this requires deeper customization).get() could become a bottleneck. Mitigation: Pre-load holidays at app boot or use Laravel’s booted callback.Artisan::schedule()) or event system (e.g., HolidayAdded events).holidays table if needed.composer require spatie/holidays
Publish config (if needed) via:
php artisan vendor:publish --provider="Spatie\Holidays\HolidaysServiceProvider"
$holidays = \Spatie\Holidays\Holidays::for('be')->get();
Holidays class via constructor.$holidays = Cache::remember("holidays-be-{$year}", now()->addYear(), fn() => Holidays::for('be')->get());
HolidayRepository or add a middleware to merge custom holidays:
// config/holidays.php
'custom' => [
'be' => [
'2024-12-25' => 'Company Holiday',
],
];
holidays table and hydrate it at app boot:
// AppServiceProvider@boot
Holidays::for(config('app.country'))->get()->each(fn($holiday) => Holiday::updateOrCreate(...));
is_holiday flag).update or Laravel’s package:update to patch.dd(Holidays::for('us')->get()) to inspect raw data.get() may take ~50–200ms (depends on country complexity). Mitigate with caching.holidays table is indexed by country and date.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package update breaks logic | Holiday data errors | Test updates in staging; use composer why-not to check dependencies. |
| Caching issues | Stale holiday data | Use short TTLs (e.g., 1 day) or invalidate cache on app updates. |
| Country code mismatch | Wrong holidays returned | Validate country codes early (e.g., middleware). |
| Custom holiday logic fails | Inconsistent overrides | Unit test custom holiday merges. |
| Timezone conflicts | Holiday dates misaligned | Normalize to UTC or app’s default timezone. |
Holidays::for()->get().Holidays class to test holiday-aware logic (e.g., "skip task if holiday").How can I help you explore Laravel packages today?