Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

A package to manage events on a Google Calendar

Original – by Freek Van der Herten – 3 minute read

Like previously mentioned we're currently building a new dashboard to display on our wall mounted TV at the office. One of the things we want to show on that dashboard are important events for our company. Things like when a site goes live, when there's a conference we're going to visit, when we're doing our monthly visit to our favourite Italian restaurant and so on. We manage these events on a Google Calendar. To make working with such a calendar real easy we've made a new package called laravel-google-calendar.

The steps required to install the package should be very familiar: pull it in via Composer, register a service provider / facade and finally publish a config file. After that you'll need to get some authentication credentials from Google. Normally this takes quite some time as the google docs are very confusing, but if you follow my previous blogpost on the subject you'll be set up in no time.

With the package fully installed 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->save();

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

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

// get all future events on a calendar, returns a Collection
$events = Event::get();
$firstEvent = $events->first();

// find a specific event and update item
$event = Event::find($eventId)
$event->name = 'My updated title' 
$event->save();

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

It's also possible to work with multiple calendars. The create, get and find methods take a second parameter $calendarId.

The Google Calendar API provides many options. It's a big beast really. This package doesn't support all those options. For instance recurring events cannot be managed properly with our code. But if you stick to creating events with a name, a description and a date(time) you should be fine.

We hope you'll like our package. If you have any questions or remarks on it let me know in the comments below or the issue tracker on GitHub. We've made a bunch of other packages in the past. Check out this list on our site to find out if there's something else we've made that you can use on your next project.

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

Comments

What are your thoughts on "A package to manage events on a Google Calendar"?

Comments powered by Laravel Comments
Want to join the conversation? Log in or create an account to post a comment.