- How do I create a Google Calendar link for an event in Laravel using spatie/calendar-links?
- Use the fluent API: `Link::create('Event Title', $startDateTime, $endDateTime)->google()`. This generates a URL like `https://calendar.google.com/...` that users can click to add the event to their Google Calendar. Ensure `$startDateTime` and `$endDateTime` are `DateTime` objects.
- Does this package support recurring events (e.g., weekly meetings)?
- No, this package is designed for one-off events. For recurring events, consider generating multiple links or using a dedicated calendar API like Google Calendar’s API. The package focuses on simplicity for single-instance events.
- Can I generate ICS files for Outlook or Apple Calendar?
- Yes. Use `Link::create(...)->ical()` to generate an ICS file. The output is compatible with Outlook, Apple Calendar, and other iCal-supporting clients. You can embed the ICS content in a downloadable link or email attachment.
- What Laravel versions does spatie/calendar-links support?
- The package supports Laravel 8.x through 11.x. It requires PHP 8.0+ and has no framework-specific dependencies, making it a safe addition to modern Laravel applications. No breaking changes have been introduced in recent releases.
- How do I integrate this into a Laravel Blade template?
- Call the package in your Blade view: `{{ Link::create('Event', $start, $end)->google() }}`. For ICS downloads, use a route with `response()->streamDownload()` to serve the generated ICS content. Example: `return response()->streamDownload(...)->withHeaders(['Content-Type' => 'text/calendar']);`
- Is there a way to customize the calendar provider URL (e.g., for Outlook)?
- Yes. Use the `custom()` method to define a custom provider URL. For example: `Link::create(...)->custom('https://outlook.office.com/...', ['param' => 'value'])` allows full control over the generated link structure.
- Should I cache the generated calendar links in production?
- Yes, caching is recommended for performance. Use Laravel’s cache system (e.g., `Cache::remember()`) to store generated links with a key like `calendar_link_{event_id}`. This avoids regenerating URLs for the same event repeatedly.
- How do I test that the generated links work correctly?
- Manually test links by pasting them into a browser or calendar app. For automated testing, validate the URL structure (e.g., check for required query parameters) and mock HTTP requests if testing integration with external APIs like Google Calendar.
- Are there any security concerns with exposing these links in public APIs?
- Yes. Validate all input `DateTime` objects to prevent malformed URLs or injection risks. Sanitize output if embedding links in user-generated content (e.g., emails or public profiles). The package itself doesn’t handle authentication for calendar providers.
- What are some alternatives to spatie/calendar-links for Laravel?
- Alternatives include custom implementations using iCal libraries like `vcalendarlib/vcalendarlib` or third-party APIs like Google Calendar’s API. However, `spatie/calendar-links` stands out for its simplicity, zero dependencies, and support for multiple providers without requiring API keys.