spatie/calendar-links
Generate “Add to calendar” links and ICS files for events. Supports Google Calendar, iCal/Apple Calendar, Outlook and more. Define title, start/end, description and location, then get shareable URLs or downloadable .ics content for your app.
composer require spatie/calendar-links.{{ $event->link->google() }}).return response()->streamDownload(...)) or links in JSON APIs.public function getCalendarLinkAttribute()).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| PHP Version | Requires PHP 8.3+ (Laravel 10+). | Low risk if using modern Laravel; otherwise, pin to v1.x (PHP 7.2+). |
| Breaking Changes | v2.0 introduced immutable dates and constructor changes. | Medium risk: Test thoroughly if upgrading from v1.x; prefer createAllDay() over constructor hacks. |
| Timezone Handling | ICS uses UTC for all-day events; Google/Yahoo may drop timezone info. | Low risk: Explicitly set timezones in DateTimeImmutable or use ->google(['timezone' => 'America/New_York']) if needed. |
| ICS Validation | Edge cases (e.g., special chars, multiline descriptions) may break parsers. | Low risk: Package handles escaping per RFC 5545; test with Outlook/Thunderbird. |
| Custom Generators | Extending generators requires PHP knowledge. | Low risk: Spatie provides clear examples; document custom logic in your codebase. |
ctz parameter) or anonymous ICS downloads.description) or use placeholders.| Component | Integration Strategy | Laravel-Specific Tools |
|---|---|---|
| Backend (PHP) | Direct use Spatie\CalendarLinks\Link in services/controllers. |
- Service Classes: Encapsulate link generation logic (e.g., CalendarLinkService). |
- Eloquent Accessors: Add calendarLinks() method to models. |
||
- API Resources: Expose links in JSON responses (e.g., EventResource::links). |
||
| Frontend | Output URLs/data URIs to JS (e.g., window.open(link)) or embed as <a> tags. |
- Blade Directives: @calendarLink('google') for reusable components. |
| - Livewire/Alpine: Dynamically generate links client-side. | ||
| Storage | Cache generated links (e.g., Redis) if regenerated frequently. | - Laravel Cache: Cache::remember(). |
| Jobs/Queues | Offload ICS generation for large events (e.g., bulk invites). | - Laravel Queues: Dispatch GenerateCalendarLinksJob. |
| Testing | Unit test generators; integration test with real calendar clients. | - Pest/Laravel Tests: Mock Link and assert outputs. |
| Concern | Solution | Example |
|---|---|---|
| PHP 8.3+ Requirement | Use v1.x if on PHP 7.4–8.1, or upgrade Laravel. |
composer require spatie/calendar-links:^1.8 |
| Laravel < 10.x | No issues; package is PHP-only. | Works in Laravel 9/10/11. |
| Custom Timezones | Pass timezone to DateTimeImmutable or use generator options. |
Link::create(..., $from->setTimezone(new DateTimeZone('UTC'))) |
| Legacy Code | Wrap in a facade to abstract breaking changes (e.g., createAllDay). |
class LegacyCalendarLink { public static function create($title, $from, $to, $allDay) { ... } } |
| Third-Party APIs | Extend generators for custom logic (e.g., adding auth tokens to URLs). | class AuthenticatedGoogle extends Google { public function __construct(string $authToken) { ... } } |
composer.json.Event::calendarLinks()).| Task | Effort | Owner | Notes |
|---|---|---|---|
| Dependency Updates | Low | DevOps/TPM | Monitor Spatie’s releases; test upgrades in staging. |
| Bug Fixes | Low | Backend Team | Most issues |
How can I help you explore Laravel packages today?