Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Hours Helper

Laravel Hours Helper Laravel Package

label84/laravel-hours-helper

Generate Laravel collections of time/date intervals for any period: build dropdown-ready schedules with custom formatting, exclusions, support for past-midnight ranges, and multi-day spans. Simple facade API to create evenly spaced slots like 08:00–09:30 every 30 minutes.

View on GitHub
Deep Wiki
Context7

Create a Collection of dates/times with a specific interval for a specific period.

Frequently asked questions about Laravel Hours Helper
How do I generate a dropdown of 30-minute slots between 9 AM and 5 PM for a Laravel Blade form?
Use the facade to create a Collection: `HoursHelper::create('09:00', '17:00', 30)` returns a Collection of strings like `['09:00', '09:30', ...]`. Loop through it in Blade with `@foreach($hours as $hour)` to render `<option>` tags. For custom formatting, pass a third parameter like `'g:i A'` to display as `9:00 AM`.
Does this package support excluding specific time ranges (e.g., lunch breaks) from the generated slots?
Yes. Pass an array of exclusion ranges as the fourth parameter. For example, `HoursHelper::create('08:00', '17:00', 60, 'H:i', [['12:00', '13:00']])` skips all slots between 12 PM and 1 PM. Exclusions are range-based and work for both time-only and datetime intervals.
Can I generate time slots spanning multiple days (e.g., for a weekly schedule) with this package?
Absolutely. Use datetime strings like `HoursHelper::create('2024-01-01 08:00', '2024-01-03 17:00', 60)` to create slots across days. The package handles past-midnight transitions automatically, so you won’t miss slots like `23:00` to `01:00`. Format the output with a pattern like `'Y-m-d H:i'` for clarity.
What Laravel versions does `label84/laravel-hours-helper` officially support, and will it work with Laravel 14?
The package supports Laravel 11–13.x as of the latest release (2026-03-16). While it’s untested on Laravel 14, the minimal dependencies (only Carbon) suggest compatibility. Check the [GitHub repo](https://github.com/Label84/laravel-hours-helper) for updates or fork the package to add Laravel 14 support if needed.
How can I integrate this with Eloquent to exclude booked time slots from my database?
Generate your base slots with `HoursHelper`, then filter them against Eloquent results. For example, fetch booked slots with `Booking::whereBetween('time', [$start, $end])->pluck('time')` and use `array_diff()` to remove overlaps. Alternatively, use `Rule::in($validSlots)` in Laravel validation to ensure form submissions match available slots.
Is there a way to handle timezones if my app serves users in different regions?
The package uses Laravel’s default timezone (from `config/app.php`). For multi-timezone support, manually create `Carbon` instances with `Carbon::createFromFormat()` in the specified timezone before passing them to `HoursHelper`. For example, use `Carbon::parse('09:00', 'America/New_York')` to generate slots in a user’s local timezone.
Will this package work well for generating large ranges (e.g., monthly or yearly slots) without memory issues?
For large ranges, consider chunking or pagination. The package returns a `Collection`, which can be processed in batches (e.g., `->chunk(100)`). For database-backed solutions, generate slots dynamically via API endpoints or use Laravel’s `cursor()` to stream results. Avoid loading entire yearly ranges into memory at once.
Can I use this with Livewire or Alpine.js for real-time UI updates (e.g., filtering available slots)?
Yes. Return the Collection as JSON from a Laravel API (`return response()->json($hours->toArray())`) and consume it in Livewire/Alpine. Use `@foreach($hours as $hour)` in Blade or `wire:model` to bind to dynamic dropdowns. For real-time filtering, dispatch events or use Alpine’s `x-model` to update slots without full page reloads.
Are there alternatives to this package for generating time intervals in Laravel, or should I consider a frontend solution?
Frontend libraries like FullCalendar or JavaScript-based solutions (e.g., `moment-range`) can generate intervals client-side, but this package reduces backend-frontend coupling by pre-generating slots. For non-linear intervals (e.g., Fibonacci spacing), you’d need a custom solution. If you need sub-minute precision (e.g., seconds), this package may require extending the interval logic.
How do I test this package in my CI pipeline, especially for edge cases like DST transitions or invalid inputs?
Mock the `HoursHelper` facade in unit tests using Laravel’s `partialMock()` or create a test double. Validate edge cases like DST by passing timezone-aware datetimes (e.g., `Carbon::parse('02:30', 'Europe/London')` during DST transitions). For invalid inputs, wrap `HoursHelper::create()` in a `try-catch` block and assert exceptions for malformed formats or unsupported intervals.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata