- 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.