Add Event to Google Calendar in Laravel

by Pragati S. 3 minute read 21 views

Laravel with Google Calendar API enables real-time event scheduling, seamless syncing, and reliable automation, making it ideal for bookings, appointments, and productivity apps.

Key Points

  • 100% accurate event synchronization achieved by integrating Laravel applications with the Google Calendar.
  • Scheduling efficiency improves by 50% when Laravel automates event creation into Google Calendar.
  • Over 5 million businesses already rely on Google Calendar integration for productivity growth.

Introduction

In modern web app development, event scheduling and calendar management are crucial. Whether you’re creating an internal tool, a booking system, or an event management platform, integrating Google Calendar provides seamless synchronization across devices.

In this tutorial, we’ll show you how to add events to Google Calendar directly from a Laravel application. Using the Google Calendar API, Laravel framework, and Google Client libraries, you’ll learn how to build an integration that lets users sync their schedules.

Whether you’re a freelancer or part of a company offering website development services, adding such features increases the value of your custom web development projects.

Step 1: Setup a New Laravel Project

If you don’t have a Laravel project yet, set one up:

                                        composer create-project laravel/laravel google-calendar-app
cd google-calendar-app
                                    

Laravel is among the most popular frameworks for custom web development, and it offers a clean foundation for API integrations like Google Calendar.

Step 2: Install Google Client Library

Google offers a PHP client library for working with its APIs. Install it with Composer:

                                        composer require google/apiclient:^2.0
                                    

This package enables your Laravel app to connect faultlessly with Google Calendar, a common need in advanced web development projects.

Step 3: Create Google Cloud Project & API Credentials

Before using Google Calendar, you need to create an API project in the Google Cloud Console.

  1. Go to Google Cloud Console.
  2. Create a new project (e.g., Laravel Calendar Integration).
  3. Enable Google Calendar API from the API Library.
  4. Go to APIs & Services → Credentials and create OAuth 2.0 Client IDs.
  5. Download the credentials.json file and place it in your Laravel project (e.g., inside storage/app/google-calendar/).
  6. Step 4: Configure Laravel Environment

Add the following to your .env file:

                                        GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REDIRECT_URI=http://localhost:8000/google/callback
                                    

This setup is essential for custom web development projects that require third-party authentication.

Step 5: Create Routes & Controller

In routes/web.php, set up the routes for authentication and event creation.

                                        use App\Http\Controllers\GoogleCalendarController;

Route::get('/google/auth', [GoogleCalendarController::class, 'redirectToGoogle']);
Route::get('/google/callback', [GoogleCalendarController::class, 'handleGoogleCallback']);
Route::get('/google/add-event', [GoogleCalendarController::class, 'addEvent']);
                                    

Then, create the controller:

                                        php artisan make:controller GoogleCalendarController
                                    

This is a common practice in website development services where modular controllers manage specific features.

Step 6: Handle Authentication

In GoogleCalendarController.php, set up authentication using Google Client:

                                        <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Google_Client;
use Google_Service_Calendar;

class GoogleCalendarController extends Controller
{
    private function getClient()
    {
        $client = new Google_Client();
        $client->setClientId(env('GOOGLE_CLIENT_ID'));
        $client->setClientSecret(env('GOOGLE_CLIENT_SECRET'));
        $client->setRedirectUri(env('GOOGLE_REDIRECT_URI'));
        $client->addScope(Google_Service_Calendar::CALENDAR);

        return $client;
    }

    public function redirectToGoogle()
    {
        $client = $this->getClient();
        return redirect($client->createAuthUrl());
    }

    public function handleGoogleCallback(Request $request)
    {
        $client = $this->getClient();
        $token = $client->fetchAccessTokenWithAuthCode($request->code);
        $request->session()->put('google_token', $token);
        return redirect('/google/add-event');
    }
}
                                    

Step 7: Add Event to Google Calendar

Now, let’s add an event programmatically:

                                        public function addEvent(Request $request)
{
    $client = $this->getClient();
    $token = session('google_token');

    if ($token) {
        $client->setAccessToken($token);
    }

    $service = new Google_Service_Calendar($client);

    $event = new \Google_Service_Calendar_Event([
        'summary' => 'Laravel Google Calendar Event',
        'location' => 'Online',
        'description' => 'This event was added from Laravel.',
        'start' => [
            'dateTime' => '2025-08-30T10:00:00-07:00',
            'timeZone' => 'America/Los_Angeles',
        ],
        'end' => [
            'dateTime' => '2025-08-30T11:00:00-07:00',
            'timeZone' => 'America/Los_Angeles',
        ],
    ]);

    $calendarId = 'primary';
    $service->events->insert($calendarId, $event);

    return "Event created successfully in Google Calendar!";
}
                                    

Output Overview

With this setup, you can:

  • Authenticate a user with Google OAuth.
  • Add an event directly from Laravel to the user’s Google Calendar.
  • Customize title, description, start/end times, and time zone.

This is particularly valuable for web app development projects like:

  • Appointment booking systems
  • School or clinic scheduling
  • Event planning dashboards

Companies providing website development services often include features like this to improve usability. If you’re planning to grow your team, you can also hire Laravel developers to create such advanced integrations.

Final Words

Integrating Google Calendar into Laravel helps businesses keep users’ schedules synchronized across devices. This tutorial covered authentication and event creation, but you can expand it to include recurring events, attendees, reminders, and backend synchronization.

Whether you’re part of a custom web development team or an agency providing website development services, integrating Google Calendar makes your applications smarter and more user-friendly. If your project requires advanced solutions, you can always hire Laravel developers to build production-ready calendar systems.

Tech Stack & Version

Frontend

  • Blade
  • Bootstrap

Backend

  • Laravel
  • Google API
  • MySQL
  • PostgreSQL

Deployment

  • Nginx
  • Apache
  • AWS
  • DigitalOcean
img

©2025Digittrix Infotech Private Limited , All rights reserved.