PHPackages                             dvico/google-calendar - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. dvico/google-calendar

ActiveLibrary

dvico/google-calendar
=====================

Manage events on a Google Calendar

2.3.2(7y ago)014MITPHPPHP ~5.6 || ^7.0

Since May 25Pushed 7y agoCompare

[ Source](https://github.com/dvico/laravel-google-calendar)[ Packagist](https://packagist.org/packages/dvico/google-calendar)[ Docs](https://github.com/dvico/laravel-google-calendar)[ RSS](/packages/dvico-google-calendar/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (6)Versions (16)Used By (0)

Manage events on a Google Calendar
==================================

[](#manage-events-on-a-google-calendar)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a47c398db0c12dac2e6fb2f815f56b171d6ded7dc55942b666424eacd70c7b11/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d676f6f676c652d63616c656e6461722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-google-calendar)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/00b8db7d3a71dddb264b7b6fbe35eb6c8874eba00c32bc473fa49b3c2e2e4c95/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f6c61726176656c2d676f6f676c652d63616c656e6461722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/laravel-google-calendar)[![SensioLabsInsight](https://camo.githubusercontent.com/be6c8f8e643cf1bdeedba2e797c5ea12bd3c706e7a9cbbb89b2e16d4024f7f14/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f61393636343132622d303931622d343430372d623530392d3666373437323933356230652e7376673f7374796c653d666c61742d737175617265)](https://insight.sensiolabs.com/projects/a966412b-091b-4407-b509-6f7472935b0e)[![Quality Score](https://camo.githubusercontent.com/2408e829d44906a6f0ca14264d98ad33e18f81ab611ad652722818d868274f5a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f6c61726176656c2d676f6f676c652d63616c656e6461722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/laravel-google-calendar)[![StyleCI](https://camo.githubusercontent.com/85567fa7e5d71d235604716e48e907fdd4dc4a1ad1bbe0663ca1baa37cbe9aee/68747470733a2f2f7374796c6563692e696f2f7265706f732f35383330353930332f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/58305903)[![Total Downloads](https://camo.githubusercontent.com/1172d5d02f2126c5738a92beeb8d7d5b739ba16a05fcb67924f544742ae38d75/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d676f6f676c652d63616c656e6461722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-google-calendar)

This package makes working with a Google Calendar a breeze. Once it has been set up you can do these things:

```
use Spatie\GoogleCalendar\Event;

//create a new event
$event = new Event;

$event->name = 'A new event';
$event->startDateTime = Carbon\Carbon::now();
$event->endDateTime = Carbon\Carbon::now()->addHour();
$event->addAttendee(['email' => 'youremail@gmail.com']);
$event->addAttendee(['email' => 'anotherEmail@gmail.com']);

$event->save();

// get all future events on a calendar
$events = Event::get();

// update existing event
$firstEvent = $events->first();
$firstEvent->name = 'updated name';
$firstEvent->save();

$firstEvent->update(['name' => 'updated again']);

// create a new event
Event::create([
   'name' => 'A new event',
   'startDateTime' => Carbon\Carbon::now(),
   'endDateTime' => Carbon\Carbon::now()->addHour(),
]);

// delete an event
$event->delete();
```

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-google-calendar
```

Next up the service provider must be registered:

```
'providers' => [
    ...
    Spatie\GoogleCalendar\GoogleCalendarServiceProvider::class,
];
```

Optionally the `Spatie\GoogleCalendar\GoogleCalendarFacade` must be registered:

```
'aliases' => [
	...
    'GoogleCalendar' => Spatie\GoogleCalendar\GoogleCalendarFacade::class,
    ...
]
```

You must publish the configuration with this command:

```
php artisan vendor:publish --provider="Spatie\GoogleCalendar\GoogleCalendarServiceProvider"
```

This will publish file called `google-calendar.php` in your config-directory with this contents:

```
return [
    /*
     * Path to the json file containing the credentials.
     */
    'service_account_credentials_json' => storage_path('app/google-calendar/service-account-credentials.json'),

    /*
     *  The id of the Google Calendar that will be used by default.
     */
    'calendar_id' => env('GOOGLE_CALENDAR_ID'),
];

```

How to obtain the credentials to communicate with Google Calendar
-----------------------------------------------------------------

[](#how-to-obtain-the-credentials-to-communicate-with-google-calendar)

The first thing you’ll need to do is to get some credentials to use Google API’s. I’m assuming that you’ve already created a Google account and are signed in. Head over to [Google API console](https://console.developers.google.com/apis) and click "Select a project" in the header.

[![1](https://camo.githubusercontent.com/422358a32a9bf94363370ef0947ad9c10667e6d6e3b5ea79bd04e4d4001a5d02/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d676f6f676c652d63616c656e6461722f76322f312e6a7067)](https://camo.githubusercontent.com/422358a32a9bf94363370ef0947ad9c10667e6d6e3b5ea79bd04e4d4001a5d02/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d676f6f676c652d63616c656e6461722f76322f312e6a7067)

Next up we must specify which API’s the project may consume. In the list of available API’s click "Google Analytics API". On the next screen click "Enable".

[![2](https://camo.githubusercontent.com/5b3233feca97510b795d2d94f3a220c2737fdbd3410da410975cb554afe4e52b/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d676f6f676c652d63616c656e6461722f76322f322e6a7067)](https://camo.githubusercontent.com/5b3233feca97510b795d2d94f3a220c2737fdbd3410da410975cb554afe4e52b/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d676f6f676c652d63616c656e6461722f76322f322e6a7067)

Now that you’ve created a project that has access to the Analytics API it’s time to download a file with these credentials. Click "Credentials" in the sidebar. You’ll want to create a "Service account key".

[![3](https://camo.githubusercontent.com/244710e0a7b6b5801dcdde3db415eac96e537721a11add4733e3de234fb84b8d/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d676f6f676c652d63616c656e6461722f76322f332e6a7067)](https://camo.githubusercontent.com/244710e0a7b6b5801dcdde3db415eac96e537721a11add4733e3de234fb84b8d/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d676f6f676c652d63616c656e6461722f76322f332e6a7067)

On the next screen you can give the service account a name. You can name it anything you’d like. In the service account id you’ll see an email address. We’ll use this email address later on in this guide. Select "JSON" as the key type and click "Create" to download the JSON file.

[![4](https://camo.githubusercontent.com/ba1b33e90126408ed0fd4e38b71e3133c7ded9300fcba3597f481c7eae9fc741/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d676f6f676c652d63616c656e6461722f76322f342e6a7067)](https://camo.githubusercontent.com/ba1b33e90126408ed0fd4e38b71e3133c7ded9300fcba3597f481c7eae9fc741/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d676f6f676c652d63616c656e6461722f76322f342e6a7067)

Save the json inside your Laravel project at the location specified in the `service_account_credentials_json` key of the config file of this package. Because the json file contains potentially sensitive information I don't recommend committing it to your git repository.

Now that everything is set up on the API site, we’ll need to configure some things on the Google Calendar site. Head over Google Calendar and view the settings of the calendar you want to work with via PHP. On the “Share this Calendar” tab add the service account id that was displayed when creating credentials on the API site.

[![5](https://camo.githubusercontent.com/a6d26e37a3513f0b8c33f40d24dbaf4a50706301c6cd02ca3b49d7bad8af0110/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d676f6f676c652d63616c656e6461722f76322f352e6a7067)](https://camo.githubusercontent.com/a6d26e37a3513f0b8c33f40d24dbaf4a50706301c6cd02ca3b49d7bad8af0110/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d676f6f676c652d63616c656e6461722f76322f352e6a7067)

Open up the “Calendar Details” tab to see the id of the calendar. You need to specify that id in the config file.

[![6](https://camo.githubusercontent.com/91e3b872e3d701b52b92a87ac71c3ab5cdc73d69b9dd4e4f624b6ce198428b4c/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d676f6f676c652d63616c656e6461722f76322f362e6a7067)](https://camo.githubusercontent.com/91e3b872e3d701b52b92a87ac71c3ab5cdc73d69b9dd4e4f624b6ce198428b4c/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d676f6f676c652d63616c656e6461722f76322f362e6a7067)

Usage
-----

[](#usage)

### Getting events

[](#getting-events)

You can fetch all events by simply calling `Event::get();` this will return all events of the coming year. An event comes in the form of a `Spatie\GoogleCalendar\Event` object.

The full signature of the function is:

```
public static function get(Carbon $startDateTime = null, Carbon $endDateTime = null, array $queryParameters = [], string $calendarId = null): Collection
```

The parameters you can pass in `$queryParameters` are listed [on the documentation on `list` at the Google Calendar API docs](https://developers.google.com/google-apps/calendar/v3/reference/events/list#request).

### Accessing start and end dates of an event

[](#accessing-start-and-end-dates-of-an-event)

You can use these getters to retrieve start and end date as [Carbon](https://github.com/briannesbitt/Carbon) instances:

```
$events = Event::get();

$events[0]->startDate;
$events[0]->startDateTime;
$events[0]->endDate;
$events[0]->endDateTime;
```

### Creating an event

[](#creating-an-event)

You can just new up a `Spatie\GoogleCalendar\Event`-object

```
$event = new Event;

$event->name = 'A new event';
$event->startDateTime = Carbon\Carbon::now();
$event->endDateTime = Carbon\Carbon::now()->addHour();

$event->save();
```

You can also call `create` statically:

```
Event::create([
   'name' => 'A new event',
   'startDateTime' => Carbon\Carbon::now(),
   'endDateTime' => Carbon\Carbon::now()->addHour(),
]);
```

This will create an event with a specific start and end time. If you want to create a full day event you must use `startDate` and `endDate` instead of `startDateTime` and `endDateTime`.

```
$event = new Event;

$event->name = 'A new full day event';
$event->startDate = Carbon\Carbon::now();
$event->endDate = Carbon\Carbon::now()->addDay();

$event->save();
```

### Getting a single event

[](#getting-a-single-event)

Google assigns a unique id to every single event. You can get this id by getting events using the `get` method and getting the `id` property on a `Spatie\GoogleCalendar\Event`-object:

```
// get the id of the first upcoming event in the calendar.
$calendarId = Event::get()->first()->id;
```

You can use this id to fetch a single event from Google:

```
Event::find($calendarId);
```

### Updating an event

[](#updating-an-event)

Easy, just change some properties and call `save()`:

```
$event = Event::find($eventId);

$event->name = 'My updated title';
$event->save();
```

Alternatively you can use the update method:

```
$event = Event::find($eventId)

$event->update(['name' => 'My updated title']);
```

### Deleting an event

[](#deleting-an-event)

Nothing to it!

```
$event = Event::find($eventId);

$event->delete();
```

### Limitations

[](#limitations)

The Google Calendar API provides many options. This package doesn't support all of them. For instance recurring events cannot be managed properly with this package. If you stick to creating events with a name and a date you should be fine.

Upgrading from v1 to v2
-----------------------

[](#upgrading-from-v1-to-v2)

The only major difference between `v1` and `v2` is that under the hood Google API v2 is used instead of v1. Here are the steps required to upgrade:

- rename the config file from `laravel-google-calendar` to `google-calendar`
- in the config file rename the `client_secret_json` key to `service_account_credentials_json`

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

A big thank you to [Sebastiaan Luca](https://github.com/sebastiaanluca) for his big help creating v2 of this package.

Support us
----------

[](#support-us)

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/spatie). All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 65.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~80 days

Total

14

Last Release

2807d ago

Major Versions

1.1.0 → 2.0.02017-07-19

1.2.0 → 2.2.02018-01-10

PHP version history (3 changes)1.0.0PHP ^7.0

2.3.0PHP ^5.6

2.3.2PHP ~5.6 || ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ba8e80c38ef44b1d94fb03e47229634562a5b725460d8a7e54c39750e425b6b5?d=identicon)[dvico](/maintainers/dvico)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (61 commits)")[![dvico](https://avatars.githubusercontent.com/u/41334495?v=4)](https://github.com/dvico "dvico (11 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (4 commits)")[![ttomdewit](https://avatars.githubusercontent.com/u/2845400?v=4)](https://github.com/ttomdewit "ttomdewit (2 commits)")[![XavRsl](https://avatars.githubusercontent.com/u/1185840?v=4)](https://github.com/XavRsl "XavRsl (2 commits)")[![glendmaatita](https://avatars.githubusercontent.com/u/966956?v=4)](https://github.com/glendmaatita "glendmaatita (1 commits)")[![Gummibeer](https://avatars.githubusercontent.com/u/6187884?v=4)](https://github.com/Gummibeer "Gummibeer (1 commits)")[![hulkur](https://avatars.githubusercontent.com/u/11457732?v=4)](https://github.com/hulkur "hulkur (1 commits)")[![luqmanrom](https://avatars.githubusercontent.com/u/6434819?v=4)](https://github.com/luqmanrom "luqmanrom (1 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![rob1121](https://avatars.githubusercontent.com/u/11769053?v=4)](https://github.com/rob1121 "rob1121 (1 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (1 commits)")[![Zn4rK](https://avatars.githubusercontent.com/u/873043?v=4)](https://github.com/Zn4rK "Zn4rK (1 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (1 commits)")[![awgv](https://avatars.githubusercontent.com/u/6409354?v=4)](https://github.com/awgv "awgv (1 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![DannyStreur](https://avatars.githubusercontent.com/u/6522773?v=4)](https://github.com/DannyStreur "DannyStreur (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dvico-google-calendar/health.svg)

```
[![Health](https://phpackages.com/badges/dvico-google-calendar/health.svg)](https://phpackages.com/packages/dvico-google-calendar)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M225](/packages/laravel-horizon)[spatie/laravel-sitemap

Create and generate sitemaps with ease

2.6k14.6M107](/packages/spatie-laravel-sitemap)[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[laravel-notification-channels/apn

Apple APN Push Notification Channel

2021.9M4](/packages/laravel-notification-channels-apn)[takielias/tablar-kit

The Elegance of Tablar Dashboard

413.4k](/packages/takielias-tablar-kit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
