PHPackages                             revolution/laravel-google-sheets - 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. [API Development](/categories/api)
4. /
5. revolution/laravel-google-sheets

ActiveLibrary[API Development](/categories/api)

revolution/laravel-google-sheets
================================

Google Sheets API v4

7.2.0(2mo ago)4483.1M—7.8%69[9 issues](https://github.com/invokable/laravel-google-sheets/issues)6MITPHPPHP ^8.3CI passing

Since Jun 26Pushed 2mo ago5 watchersCompare

[ Source](https://github.com/invokable/laravel-google-sheets)[ Packagist](https://packagist.org/packages/revolution/laravel-google-sheets)[ GitHub Sponsors](https://github.com/invokable)[ RSS](/packages/revolution-laravel-google-sheets/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (83)Used By (6)

Google Sheets API v4 for Laravel
================================

[](#google-sheets-api-v4-for-laravel)

[![packagist](https://camo.githubusercontent.com/c415e11b92be82c3e77fb9d63bf5909289935bd3bb6722bd80cdf520e5de4ff5/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f7265766f6c7574696f6e2f6c61726176656c2d676f6f676c652d736865657473)](https://packagist.org/packages/revolution/laravel-google-sheets)[![Maintainability](https://camo.githubusercontent.com/4d631d81b0c768e0bd09e029ee0b3f339e3cbc2bb2a6820c5b66408c052d5441/68747470733a2f2f716c74792e73682f6261646765732f34383361333438312d666263332d346534332d613833662d6138343361323561343564382f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/invokable/projects/laravel-google-sheets)[![Code Coverage](https://camo.githubusercontent.com/4239c09317df6c7e89201b8b389abd76a15a321f54a0f009609767ec3d393e37/68747470733a2f2f716c74792e73682f6261646765732f34383361333438312d666263332d346534332d613833662d6138343361323561343564382f746573745f636f7665726167652e737667)](https://qlty.sh/gh/invokable/projects/laravel-google-sheets)[![Ask DeepWiki](https://camo.githubusercontent.com/0f5ae213ac378635adeb5d7f13cef055ad2f7d9a47b36de7b1c67dbe09f609ca/68747470733a2f2f6465657077696b692e636f6d2f62616467652e737667)](https://deepwiki.com/invokable/laravel-google-sheets)

Overview
--------

[](#overview)

This package provides a **Laravel-idiomatic and streamlined interface** for interacting with Google Sheets API v4. It abstracts away the underlying Google PHP client complexity, letting developers read, write, update, and manage spreadsheets with expressive, fluent methods that feel natural in Laravel applications.

**Key Features:**

- **Multi-method Authentication**: Supports OAuth 2.0 (user-specific access), Service Account (server-to-server), and API key (public data access)
- **Fluent API**: Chainable methods for data and sheet operations with intuitive syntax
- **Laravel Collection Integration**: Seamlessly converts Google Sheets data into Laravel Collections for easy manipulation
- **Extensibility**: Macro system allows you to add custom methods to the main facade
- **Drive Integration**: Built-in Google Drive API support for spreadsheet management

**Common Use Cases:**

- **User Dashboards**: Display and interact with Google Sheets data in your application
- **Import/Export**: Bulk data operations between your Laravel app and Google Sheets
- **Automated Reports**: Generate and update reports programmatically
- **Multi-user Applications**: Each user can manage their own Google Sheets with proper authentication

### Concept

[](#concept)

The main purpose of this package is **reading from Google Sheets**. Instead of specifying detailed conditions before reading, it is assumed that you first retrieve all data as a Laravel Collection and then process the data on the Laravel side.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.3
- Laravel &gt;= 12.0

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

[](#installation)

### Composer

[](#composer)

```
composer require revolution/laravel-google-sheets
```

### Laravel Configuration

[](#laravel-configuration)

1. Run `php artisan vendor:publish --tag="google-config"` to publish the google config file
2. Enable Google APIs in [Google Cloud Console](https://console.cloud.google.com/):

    - **Google Sheets API**
    - **Google Drive API**
3. Choose your authentication method and configure accordingly (see [Authentication](#authentication) section below)

Demo &amp; Examples
-------------------

[](#demo--examples)

- **Working Demo**: [Laravel Google Sheets Demo](https://sheets.kawax.biz/)
- **Example Project**: [google-sheets-project](https://github.com/invokable/google-sheets-project)

**Related Google API Packages:**

- [Laravel Google Photos](https://github.com/invokable/laravel-google-photos)
- [Laravel Google Search Console](https://github.com/invokable/laravel-google-searchconsole)

Authentication
--------------

[](#authentication)

You must choose an authentication method based on your use case. This package supports three authentication methods:

> **Scopes setting is required in config/google.php for both OAuth and Service Account authentication.**Example:
>
> ```
> 'scopes' => [
>     \Google\Service\Sheets::SPREADSHEETS,
>     \Google\Service\Drive::DRIVE,
> ],
> ```

### Authentication Methods Comparison

[](#authentication-methods-comparison)

MethodUse CaseUser InteractionAccess ScopeComplexity**Service Account**Server-to-server, automated systemsNone requiredSpecific spreadsheets you own/shareMedium**OAuth 2.0**User-facing applicationsUser consent requiredUser's own spreadsheetsHigh**API Key**Public data onlyNone requiredPublic spreadsheets onlyLow### Service Account (Recommended for most applications)

[](#service-account-recommended-for-most-applications)

**Best for:** Background jobs, automated systems, server-to-server access

Access spreadsheets that your application owns or has been granted access to. No user interaction required.

```
GOOGLE_SERVICE_ENABLED=true
GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION=storage/app/google-service-account.json
```

**📖 [Complete Service Account Setup Guide →](docs/service-account.md)**

### OAuth 2.0

[](#oauth-20)

**Best for:** Applications where users access their own Google Sheets

Users grant permission to access their personal Google Sheets. Requires user consent flow.

```
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REDIRECT=https://your-app.com/auth/callback
```

**📖 [Complete OAuth Setup Guide →](docs/oauth.md)**

### API Key (Public Access Only)

[](#api-key-public-access-only)

**Best for:** Accessing publicly shared, read-only spreadsheets

Limited to reading data from spreadsheets that are publicly accessible. No authentication flow required.

```
GOOGLE_DEVELOPER_KEY=your-api-key
```

To use API Key authentication:

1. Get an API Key from [Google Cloud Console](https://console.cloud.google.com/apis/credentials)
2. Ensure your spreadsheet is publicly accessible (shared with "Anyone with the link")
3. Use the key in your application:

```
use Revolution\Google\Sheets\Facades\Sheets;

// API key is automatically used when configured
$values = Sheets::spreadsheet('public-spreadsheet-id')->sheet('Sheet1')->all();
```

**⚠️ API Key Limitations:**

- Read-only access
- Only works with publicly shared spreadsheets
- No write operations (update, append, delete)
- No access to private spreadsheets

Quick Start
-----------

[](#quick-start)

Here's how to get started quickly with each authentication method:

### Using Service Account (Recommended)

[](#using-service-account-recommended)

1. **Setup**: Follow the [Service Account Setup Guide](docs/service-account.md)
2. **Configure**: Add to your `.env` file: ```
    GOOGLE_SERVICE_ENABLED=true
    GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION=storage/app/google-service-account.json
    ```
3. **Share**: Share your Google Sheet with the service account email
4. **Use**: Start reading/writing data: ```
    use Revolution\Google\Sheets\Facades\Sheets;

    $values = Sheets::spreadsheet('your-spreadsheet-id')
        ->sheet('Sheet1')
        ->all();
    ```

### Using OAuth 2.0

[](#using-oauth-20)

1. **Setup**: Follow the [OAuth Setup Guide](docs/oauth.md)
2. **Configure**: Add OAuth credentials to your `.env` file
3. **Authenticate**: Handle user authentication flow
4. **Use**: Access user's spreadsheets: ```
    use Revolution\Google\Sheets\Facades\Sheets;

    $token = ['access_token' => $user->access_token, ...];
    $values = Sheets::setAccessToken($token)
        ->spreadsheet('user-spreadsheet-id')
        ->sheet('Sheet1')
        ->all();
    ```

### Using API Key (Public Access)

[](#using-api-key-public-access)

1. **Setup**: Get API key from Google Cloud Console
2. **Configure**: Add to your `.env` file: ```
    GOOGLE_DEVELOPER_KEY=your-api-key
    ```
3. **Use**: Read public spreadsheets: ```
    use Revolution\Google\Sheets\Facades\Sheets;

    // Works only with publicly shared spreadsheets
    $values = Sheets::spreadsheet('public-spreadsheet-id')
        ->sheet('Sheet1')
        ->all();
    ```

Usage
-----

[](#usage)

Consider this example spreadsheet structure:

idnamemail1name1mail12name2mail2Spreadsheet URL: `https://docs.google.com/spreadsheets/d/{spreadsheetID}/...`

### Service Account Usage

[](#service-account-usage)

When using Service Account authentication, no token setup is required:

```
use Revolution\Google\Sheets\Facades\Sheets;

// Service account authentication is automatic when configured
$values = Sheets::spreadsheet('spreadsheetId')->sheet('Sheet 1')->all();
// [
//   ['id', 'name', 'mail'],
//   ['1', 'name1', 'mail1'],
//   ['2', 'name2', 'mail2']
// ]
```

### OAuth Usage

[](#oauth-usage)

When using OAuth authentication, you need to set the user's access token:

```
use Revolution\Google\Sheets\Facades\Sheets;

$user = $request->user();

$token = [
    'access_token'  => $user->access_token,
    'refresh_token' => $user->refresh_token,
    'expires_in'    => $user->expires_in,
    'created'       => $user->updated_at->getTimestamp(),
];

// all() returns array
$values = Sheets::setAccessToken($token)->spreadsheet('spreadsheetId')->sheet('Sheet 1')->all();
// [
//   ['id', 'name', 'mail'],
//   ['1', 'name1', 'mail1'],
//   ['2', 'name1', 'mail2']
// ]
```

### Get a sheet's values with the header as the key (Recommended)

[](#get-a-sheets-values-with-the-header-as-the-key-recommended)

Collection conversion is simple and subsequent processing is flexible, so this method is recommended.

```
use Revolution\Google\Sheets\Facades\Sheets;

// get() returns Laravel Collection
$rows = Sheets::sheet('Sheet 1')->get();

$header = $rows->pull(0);
$values = Sheets::collection(header: $header, rows: $rows);
$values->toArray()
// [
//   ['id' => '1', 'name' => 'name1', 'mail' => 'mail1'],
//   ['id' => '2', 'name' => 'name2', 'mail' => 'mail2']
// ]
```

Blade

```
@foreach($values as $value)
  {{ data_get($value, 'name') }}
@endforeach
```

### Using A1 Notation

[](#using-a1-notation)

```
use Revolution\Google\Sheets\Facades\Sheets;

$values = Sheets::sheet('Sheet 1')->range('A1:B2')->all();
// [
//   ['id', 'name'],
//   ['1', 'name1'],
// ]
```

### About A1 Notation

[](#about-a1-notation)

A1 Notation is the standard way to specify a cell or range in Google Sheets (e.g., 'A1', 'A1:B2').

- 'A1' refers to the cell at column A and row 1.
- 'A1:B2' refers to the range from cell A1 to B2 (rectangle).
- 'A:B' refers to all rows in columns A and B.

If you are not familiar with A1 Notation or your range is dynamic/complicated, it is often easier to fetch all data and use Laravel Collections to process/filter it after retrieval.

### Updating a specific range

[](#updating-a-specific-range)

```
use Revolution\Google\Sheets\Facades\Sheets;

Sheets::sheet('Sheet 1')->range('A4')->update([['3', 'name3', 'mail3']]);
$values = Sheets::range('')->all();
// [
//   ['id', 'name', 'mail'],
//   ['1', 'name1', 'mail1'],
//   ['2', 'name1', 'mail2'],
//   ['3', 'name3', 'mail3']
// ]
```

### Append a set of values to a sheet

[](#append-a-set-of-values-to-a-sheet)

```
use Revolution\Google\Sheets\Facades\Sheets;

// When we don't provide a specific range, the sheet becomes the default range
Sheets::sheet('Sheet 1')->append([['3', 'name3', 'mail3']]);
$values = Sheets::all();
// [
//   ['id', 'name', 'mail'],
//   ['1', 'name1', 'mail1'],
//   ['2', 'name1', 'mail2'],
//   ['3', 'name3', 'mail3']
// ]
```

### Append a set of values with keys

[](#append-a-set-of-values-with-keys)

```
use Revolution\Google\Sheets\Facades\Sheets;

// When providing an associative array, values get matched up to the headers in the provided sheet
Sheets::sheet('Sheet 1')->append([['name' => 'name4', 'mail' => 'mail4', 'id' => 4]]);
$values = Sheets::all();
// [
//   ['id', 'name', 'mail'],
//   ['1', 'name1', 'mail1'],
//   ['2', 'name1', 'mail2'],
//   ['3', 'name3', 'mail3'],
//   ['4', 'name4', 'mail4'],
// ]
```

### Add a new sheet

[](#add-a-new-sheet)

```
use Revolution\Google\Sheets\Facades\Sheets;

Sheets::spreadsheetByTitle($title)->addSheet('New Sheet Title');
```

### Deleting a sheet

[](#deleting-a-sheet)

```
use Revolution\Google\Sheets\Facades\Sheets;

Sheets::spreadsheetByTitle($title)->deleteSheet('Old Sheet Title');
```

### Specifying query parameters

[](#specifying-query-parameters)

```
use Revolution\Google\Sheets\Facades\Sheets;

$values = Sheets::sheet('Sheet 1')->majorDimension('DIMENSION_UNSPECIFIED')
                                  ->valueRenderOption('FORMATTED_VALUE')
                                  ->dateTimeRenderOption('SERIAL_NUMBER')
                                  ->all();
```

Use original Google\\Service\\Sheets
------------------------------------

[](#use-original-googleservicesheets)

```
use Revolution\Google\Sheets\Facades\Sheets;

$sheets->spreadsheets->...
$sheets->spreadsheets_sheets->...
$sheets->spreadsheets_values->...

Sheets::getService()->spreadsheets->...
```

see

FAQ
---

[](#faq)

### Which authentication method should I use?

[](#which-authentication-method-should-i-use)

- **Service Account**: Best for most Laravel applications, automated systems, and background jobs
- **OAuth 2.0**: Use when users need to access their own Google Sheets
- **API Key**: Only for reading public spreadsheets (very limited use cases)

### How do I share a spreadsheet with my Service Account?

[](#how-do-i-share-a-spreadsheet-with-my-service-account)

1. Open your Google Sheet
2. Click the "Share" button
3. Find the `client_email` in your service account JSON file
4. Share the spreadsheet with this email address
5. Grant "Editor" permissions for read/write access

### Can I access multiple spreadsheets?

[](#can-i-access-multiple-spreadsheets)

Yes! You can access any spreadsheet that:

- Is shared with your service account (Service Account method)
- The authenticated user has access to (OAuth method)
- Is publicly accessible (API Key method)

### How do I handle authentication errors?

[](#how-do-i-handle-authentication-errors)

Common solutions:

- **Service Account**: Ensure the spreadsheet is shared with the service account email
- **OAuth**: Check if the access token is expired and refresh it
- **API Key**: Verify the spreadsheet is publicly accessible

### How do I deploy this to production?

[](#how-do-i-deploy-this-to-production)

- Store service account credentials securely (outside web root)
- Use environment variables for all configuration
- Never commit credential files to version control
- Consider using different service accounts for different environments

LICENSE
-------

[](#license)

MIT License

###  Health Score

74

—

ExcellentBetter than 100% of packages

Maintenance86

Actively maintained with recent releases

Popularity64

Solid adoption and visibility

Community32

Small or concentrated contributor base

Maturity94

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 84.9% 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 ~44 days

Recently: every ~63 days

Total

81

Last Release

86d ago

Major Versions

3.2.13 → 4.0.02019-02-27

3.3.0 → 4.0.22019-05-25

4.0.x-dev → 5.0.02019-09-07

5.x-dev → 6.0.02022-04-22

6.x-dev → 7.0.02024-05-25

PHP version history (14 changes)1.0.0PHP &gt;=5.6

1.0.3PHP &gt;=5.5.9

2.3.2PHP ^5.6.4 || ^7.0

3.0.0PHP &gt;=7.0.0

4.0.0PHP &gt;=7.1.3

5.0.0PHP ^7.2

5.0.1PHP ^7.2||^8.0

5.5.0PHP ^7.3||^8.0

5.7.0PHP ^7.4||^8.0

6.0.0PHP ^8.0

6.2.0PHP &gt;=8.0

6.3.0PHP ^8.1

7.0.0PHP ^8.2

7.2.0PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/77618633?v=4)[Revolution](/maintainers/revolution)[@Revolution](https://github.com/Revolution)

---

Top Contributors

[![kawax](https://avatars.githubusercontent.com/u/1502086?v=4)](https://github.com/kawax "kawax (241 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (18 commits)")[![calebanthony](https://avatars.githubusercontent.com/u/5722251?v=4)](https://github.com/calebanthony "calebanthony (10 commits)")[![negoziator](https://avatars.githubusercontent.com/u/2228675?v=4)](https://github.com/negoziator "negoziator (7 commits)")[![Nuvm](https://avatars.githubusercontent.com/u/10555043?v=4)](https://github.com/Nuvm "Nuvm (1 commits)")[![r15ch13](https://avatars.githubusercontent.com/u/432127?v=4)](https://github.com/r15ch13 "r15ch13 (1 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")[![adammatysiak](https://avatars.githubusercontent.com/u/25105267?v=4)](https://github.com/adammatysiak "adammatysiak (1 commits)")[![timbroder](https://avatars.githubusercontent.com/u/121503?v=4)](https://github.com/timbroder "timbroder (1 commits)")[![awoyele](https://avatars.githubusercontent.com/u/16243076?v=4)](https://github.com/awoyele "awoyele (1 commits)")[![devin-ai-integration[bot]](https://avatars.githubusercontent.com/in/811515?v=4)](https://github.com/devin-ai-integration[bot] "devin-ai-integration[bot] (1 commits)")[![nino-onepilot](https://avatars.githubusercontent.com/u/155549303?v=4)](https://github.com/nino-onepilot "nino-onepilot (1 commits)")

---

Tags

google-sheetslaravelgooglesheets

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/revolution-laravel-google-sheets/health.svg)

```
[![Health](https://phpackages.com/badges/revolution-laravel-google-sheets/health.svg)](https://phpackages.com/packages/revolution-laravel-google-sheets)
```

###  Alternatives

[pulkitjalan/google-apiclient

Google api php client wrapper with Cloud Platform and Laravel support

2582.9M5](/packages/pulkitjalan-google-apiclient)[thujohn/analytics

Google Analytics for Laravel 4

113108.7k1](/packages/thujohn-analytics)[schulzefelix/laravel-search-console

A Laravel package to retrieve data from Google Search Console

5037.8k1](/packages/schulzefelix-laravel-search-console)[scottybo/laravel-google-my-business

A package for Laravel which implements the Google My Business API

3360.3k](/packages/scottybo-laravel-google-my-business)

PHPackages © 2026

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