### Install spatie/laravel-google-calendar via Composer Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Command to add the package to your Laravel project using Composer. ```bash composer require spatie/laravel-google-calendar ``` -------------------------------- ### Google Calendar Package Configuration Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Example configuration file for the Google Calendar package, detailing authentication profiles (service account, OAuth) and default calendar ID. ```php return [ 'default_auth_profile' => env('GOOGLE_CALENDAR_AUTH_PROFILE', 'service_account'), 'auth_profiles' => [ /* * Authenticate using a service account. */ 'service_account' => [ /* * Path to the json file containing the credentials. */ 'credentials_json' => storage_path('app/google-calendar/service-account-credentials.json'), ], /* * Authenticate with actual google user account. */ 'oauth' => [ /* * Path to the json file containing the oauth2 credentials. */ 'credentials_json' => storage_path('app/google-calendar/oauth-credentials.json'), /* * Path to the json file containing the oauth2 token. */ 'token_json' => storage_path('app/google-calendar/oauth-token.json'), ], ], /* * The id of the Google Calendar that will be used by default. */ 'calendar_id' => env('GOOGLE_CALENDAR_ID'), ]; ``` -------------------------------- ### Get All Events Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Fetch all events from Google Calendar. By default, it retrieves events for the coming year. Each event is returned as a Spatie\GoogleCalendar\Event object. ```php $events = Event::get(); ``` -------------------------------- ### Create Google Calendar Event (Timed) Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Demonstrates how to create a new Google Calendar event with specific start and end times using the Spatie Google Calendar package. It shows both instantiating the Event object and using the static create method. Requires the Carbon library for date/time handling. ```php $event = new \Spatie\GoogleCalendar\Event; $event->name = 'A new event'; $event->startDateTime = \Carbon\Carbon::now(); $event->endDateTime = \Carbon\Carbon::now()->addHour(); $event->save(); ``` ```php \Spatie\GoogleCalendar\Event::create([ 'name' => 'A new event', 'startDateTime' => \Carbon\Carbon::now(), 'endDateTime' => \Carbon\Carbon::now()->addHour(), ]); ``` -------------------------------- ### Accessing Event Dates Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Demonstrates how to access the start and end dates of an event object using dedicated getters. These return dates as Carbon instances for easy manipulation. ```php $events = Event::get(); $events[0]->startDate; $events[0]->startDateTime; $events[0]->endDate; $events[0]->endDateTime; ``` -------------------------------- ### Get Event ID and Fetch Single Event Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Explains how to retrieve the unique ID of a Google Calendar event, either from an existing event object or after saving a new one. The ID can then be used with the `find` method to fetch a specific event. ```php // Get the id of the first upcoming event $eventId = \Spatie\GoogleCalendar\Event::get()->first()->id; // Get the id after creating and saving an event $event = new \Spatie\GoogleCalendar\Event; $newEvent = $event->save(); echo $newEvent->id; // display the event id // Fetch a single event using its ID $singleEvent = \Spatie\GoogleCalendar\Event::find($eventId); ``` -------------------------------- ### Run Tests Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Command to execute the test suite for the Spatie Laravel Google Calendar package using Composer. ```bash composer test ``` -------------------------------- ### Quick Save Google Calendar Event Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Shows how to quickly create an event from a simple text string using the `quickSave` method on an Event object or the `quickCreate` static method. This is useful for parsing natural language date/time descriptions. ```php $event = new \Spatie\GoogleCalendar\Event(); $event->quickSave('Appointment at Somewhere on April 25 10am-10:25am'); ``` ```php \Spatie\GoogleCalendar\Event::quickCreate('Appointment at Somewhere on April 25 10am-10:25am'); ``` -------------------------------- ### Publish Laravel Google Calendar Configuration Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Command to publish the package's configuration file to your Laravel project. ```bash php artisan vendor:publish --provider="Spatie\GoogleCalendar\GoogleCalendarServiceProvider" ``` -------------------------------- ### Create Google Calendar Event (Full Day) Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Illustrates creating a full-day event in Google Calendar using the Spatie package. This method uses `startDate` and `endDate` properties instead of `startDateTime` and `endDateTime`. Requires the Carbon library. ```php $event = new \Spatie\GoogleCalendar\Event; $event->name = 'A new full day event'; $event->startDate = \Carbon\Carbon::now(); $event->endDate = \Carbon\Carbon::now()->addDay(); $event->save(); ``` -------------------------------- ### Publish Package Configuration Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Force the publication of the package's configuration file using an Artisan command. This is useful when upgrading from older versions or to ensure the latest configuration is available. ```bash php artisan vendor:publish --provider="Spatie\GoogleCalendar\GoogleCalendarServiceProvider" --force ``` -------------------------------- ### Create, Update, and Manage Google Calendar Events Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Demonstrates how to create new Google Calendar events, set properties like name, description, start/end times, add attendees, and optionally include a Google Meet link. It also covers updating existing events and saving changes. ```php use Spatie\GoogleCalendar\Event; // create a new event $event = new Event; $event->name = 'A new event'; $event->description = 'Event description'; $event->startDateTime = Carbon\Carbon::now(); $event->endDateTime = Carbon\Carbon::now()->addHour(); $event->addAttendee([ 'email' => 'john@example.com', 'name' => 'John Doe', 'comment' => 'Lorum ipsum', 'responseStatus' => 'needsAction', ]); $event->addAttendee(['email' => 'anotherEmail@gmail.com']); $event->addMeetLink(); // optionally add a google meet link to the event $event->save(); // 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(), ]); ``` -------------------------------- ### Event::get() Method Signature Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Provides the full signature for the `Event::get()` method, detailing its parameters for filtering events by date, query parameters, and calendar ID. ```APIDOC Event::get(Carbon $startDateTime = null, Carbon $endDateTime = null, array $queryParameters = [], string $calendarId = null): Collection - Fetches events from Google Calendar. - Parameters: - startDateTime: Optional. The start date/time for filtering events (Carbon instance). - endDateTime: Optional. The end date/time for filtering events (Carbon instance). - queryParameters: Optional. An array of additional query parameters for the Google Calendar API list method. - calendarId: Optional. The ID of the specific calendar to fetch events from. - Returns: A Laravel Collection of Spatie\GoogleCalendar\Event objects. ``` -------------------------------- ### Retrieve Future Google Calendar Events Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Shows how to fetch all future events from a Google Calendar. This is useful for listing scheduled appointments or tasks. ```php // get all future events on a calendar $events = Event::get(); ``` -------------------------------- ### Set OAuth2 Authentication Profile Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Configure the package to use OAuth2 authentication by setting an environment variable. This enables authentication with a personal Google account. ```dotenv GOOGLE_CALENDAR_AUTH_PROFILE=oauth ``` -------------------------------- ### Set Event Source URL Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Shows how to set source URLs for a Google Calendar event, which are visible only to the event creator. This functionality requires OAuth authentication and involves assigning an associative array to the `source` property. ```php $yourEvent->source = [ 'title' => 'Test Source Title', 'url' => 'http://testsource.url', ]; ``` -------------------------------- ### Update Google Calendar Event Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Demonstrates updating an existing Google Calendar event. Changes can be made by directly modifying properties and calling `save()`, or by using the `update` method with an associative array of changes. ```php $event = \Spatie\GoogleCalendar\Event::find($eventId); $event->name = 'My updated title'; $event->save(); ``` ```php $event = \Spatie\GoogleCalendar\Event::find($eventId); $event->update(['name' => 'My updated title']); ``` -------------------------------- ### Set Event Color Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Demonstrates how to assign a specific color to a Google Calendar event using the `setColorId` method. The color ID must be between 1 and 11, corresponding to the predefined colors in the Google Calendar API. ```php $yourevent->setColorId(11); ``` -------------------------------- ### Delete a Google Calendar Event Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Illustrates the process of removing an event from the Google Calendar. This typically involves having an event object and calling the delete method. ```php $event->delete(); ``` -------------------------------- ### Delete Google Calendar Event Source: https://github.com/spatie/laravel-google-calendar/blob/main/README.md Provides the code snippet for deleting a Google Calendar event. After fetching an event using its ID, the `delete` method can be called on the event object. ```php $event = \Spatie\GoogleCalendar\Event::find($eventId); $event->delete(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.