fredbradley/annual-leave-widget 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fredbradley/annual-leave-widget

Composer 安装命令:

composer require fredbradley/annual-leave-widget

包简介

A Laravel package for displaying annual leave events from Google Calendar ICS feeds

README 文档

README

? A Laravel package for displaying annual leave events from Google Calendar ICS feeds in your Laravel 12/13 application.

Requirements

  • PHP 8.5+
  • Laravel 12.x or 13.x

Installation

Install the package via Composer:

composer require fredbradley/annual-leave-widget

The package will automatically register itself via Laravel's package auto-discovery.

Configuration

1. Publish the Configuration File (Optional)

If you want to customize the configuration, publish the config file:

php artisan vendor:publish --tag=annual-leave-config

This will create a config/annual_leave.php file in your application.

2. Add Your Google Calendar ICS URL

Add your Google Calendar ICS URL to your .env file:

GOOGLE_CALENDAR_ICS_URI=https://calendar.google.com/calendar/ical/your-calendar-id/public/basic.ics

How to Get Your Google Calendar ICS URL

  1. Open Google Calendar
  2. Click on the three dots next to the calendar you want to share
  3. Select "Settings and sharing"
  4. Scroll down to "Integrate calendar"
  5. Copy the "Secret address in iCal format" URL

Getting iCal Link

3. Optional Environment Variables

You can also configure the following in your .env file:

# Timezone for parsing calendar events (default: Europe/London)
ANNUAL_LEAVE_TIMEZONE=Europe/London

# Maximum number of events to display (default: 12)
ANNUAL_LEAVE_MAX_EVENTS=12

Usage

Basic Usage

Once installed and configured, the package automatically registers a route at /annual-leave that displays the widget.

Visit: https://your-app.test/annual-leave

Custom Views

If you want to customize the view, publish the views:

php artisan vendor:publish --tag=annual-leave-views

This will create views in resources/views/vendor/annual-leave/ which you can customize.

Using the Widget in Your Own Views

You can also include the widget in your own views:

@include('annual-leave::widget', ['events' => $events])

To get the events in your controller:

use CranleighSchool\AnnualLeave\IcsParser;

public function myMethod()
{
    $parser = new IcsParser(config('annual_leave.google_calendar_ics_uri'));
    $events = $parser->parse();

    return view('your-view', compact('events'));
}

JSON API Endpoint

The package also provides a JSON API endpoint for consuming applications:

Endpoint: GET /annual-leave/json

Response Format:

{
  "success": true,
  "count": 12,
  "events": [
    {
      "title": "John Doe - Annual Leave",
      "start_timestamp": 1735689600,
      "end_timestamp": 1736294399,
      "start_date": "2025-01-01",
      "end_date": "2025-01-07",
      "start_datetime": "2025-01-01T00:00:00+00:00",
      "end_datetime": "2025-01-07T23:59:59+00:00",
      "readable_start": "01 Jan",
      "readable_end": "07 Jan",
      "readable_range": "01 Jan-07 Jan",
      "timezone": "Europe/London",
      "is_active": true
    }
  ]
}

Error Response:

{
  "error": "GOOGLE_CALENDAR_ICS_URI is not configured"
}

Using the JSON API:

// JavaScript/Fetch example
fetch('/annual-leave/json')
  .then(response => response.json())
  .then(data => {
    console.log(`Found ${data.count} events`);
    data.events.forEach(event => {
      console.log(`${event.title}: ${event.readable_range}`);
    });
  });
// PHP/Laravel HTTP Client example
$response = Http::get('https://your-app.test/annual-leave/json');
$events = $response->json('events');

Styling

The widget outputs HTML with the following structure:

<div class="leavedatablock">
    <table>
        <tr class="today"><!-- class 'today' is added for current events -->
            <td>
                <span class="the_date">01 Jan-05 Jan: </span>
                Event Title
            </td>
        </tr>
    </table>
</div>

You can add your own CSS to style the widget. Events that are currently active (today is between start and end dates) will have the today class applied to the <tr> element.

Configuration Options

The config/annual_leave.php file contains the following options:

Option Environment Variable Default Description
google_calendar_ics_uri GOOGLE_CALENDAR_ICS_URI null The URL to your Google Calendar ICS file
timezone ANNUAL_LEAVE_TIMEZONE Europe/London Default timezone for parsing events
max_events ANNUAL_LEAVE_MAX_EVENTS 12 Maximum number of upcoming events to display
enable_routes ANNUAL_LEAVE_ENABLE_ROUTES true Whether to automatically register routes
route_prefix ANNUAL_LEAVE_ROUTE_PREFIX annual-leave URL prefix for package routes
route_middleware N/A [] Middleware to apply to routes (set in config file)

License

This package is open-sourced software. Please check the repository for license information.

Credits

fredbradley/annual-leave-widget 适用场景与选型建议

fredbradley/annual-leave-widget 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「calendar」 「laravel」 「widget」 「ics」 「google-calendar」 「leave-management」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fredbradley/annual-leave-widget 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fredbradley/annual-leave-widget 我们能提供哪些服务?
定制开发 / 二次开发

基于 fredbradley/annual-leave-widget 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 40
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-24