PHPackages                             olamilekan/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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. olamilekan/laravel-google-sheets

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

olamilekan/laravel-google-sheets
================================

A Laravel package for working with Google Sheets API with support for multiple spreadsheet connections

v1.0.0(1mo ago)00MITPHPPHP ^8.1

Since Mar 30Pushed 1mo agoCompare

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

READMEChangelogDependencies (4)Versions (2)Used By (0)

Laravel Google Sheets
=====================

[](#laravel-google-sheets)

A fluent Laravel package for reading, writing, and managing Google Sheets with first-class support for multiple spreadsheet connections.

---

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

[](#requirements)

- PHP 8.1+
- Laravel 10, 11, or 12
- A Google Cloud project with the Sheets API enabled
- A service account JSON credentials file

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

[](#installation)

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

Publish the configuration file:

```
php artisan vendor:publish --tag=google-sheets-config
```

Configuration
-------------

[](#configuration)

### 1. Credentials

[](#1-credentials)

Place your service account JSON file somewhere secure (e.g. `storage/app/google/service-account.json`) and set the path in your `.env`:

```
GOOGLE_SHEETS_CREDENTIALS_PATH=/path/to/service-account.json
```

### 2. Spreadsheet Connections

[](#2-spreadsheet-connections)

Define as many named connections as you need in `config/google-sheets.php`:

```
'sheets' => [

    'default' => [
        'spreadsheet_id' => env('GOOGLE_SHEETS_SPREADSHEET_ID'),
        'sheet' => 'Sheet1',
    ],

    'users' => [
        'spreadsheet_id' => env('GOOGLE_SHEETS_USERS_SPREADSHEET_ID'),
        'sheet' => 'Users',
    ],

    'reports' => [
        'spreadsheet_id' => env('GOOGLE_SHEETS_REPORTS_SPREADSHEET_ID'),
        'sheet' => 'Monthly',
    ],

],
```

Set the default connection:

```
GOOGLE_SHEETS_DEFAULT_CONNECTION=default
GOOGLE_SHEETS_SPREADSHEET_ID=your-spreadsheet-id-here
```

---

Usage
-----

[](#usage)

### Using the Facade

[](#using-the-facade)

```
use Olamilekan\GoogleSheets\Facades\GoogleSheets;
```

### Reading Data

[](#reading-data)

```
// All rows from the default connection (first row treated as headers)
$rows = GoogleSheets::all();

// Specific range
$rows = GoogleSheets::range('A1:D10')->get();

// First row only
$row = GoogleSheets::first();

// Get column headers
$headers = GoogleSheets::headers();

// Without header mapping (raw arrays)
$rows = GoogleSheets::connection('users')->withoutHeaders()->get();
```

### Querying Data

[](#querying-data)

```
// Find rows where a column matches a value
$admins = GoogleSheets::find('role', 'admin');

// Where clause with operators
$highScores = GoogleSheets::where('score', '>=', 90);

// Partial text matching
$results = GoogleSheets::where('name', 'like', 'john');
```

### Writing Data

[](#writing-data)

```
// Append rows
GoogleSheets::append([
    ['Alice', 'alice@example.com', 'admin'],
    ['Bob', 'bob@example.com', 'user'],
]);

// Update a specific range
GoogleSheets::range('A2:C2')->update([
    ['Alice Updated', 'alice-new@example.com', 'superadmin'],
]);

// Batch update multiple ranges at once
GoogleSheets::batchUpdate([
    'A2:C2' => [['Alice', 'alice@example.com', 'admin']],
    'A3:C3' => [['Bob', 'bob@example.com', 'user']],
]);

// Clear a range
GoogleSheets::range('A2:C100')->clear();
```

### Multiple Connections

[](#multiple-connections)

```
// Switch between configured connections
$users  = GoogleSheets::connection('users')->all();
$reports = GoogleSheets::connection('reports')->all();

// Create an ad-hoc connection to any spreadsheet
$data = GoogleSheets::make('some-spreadsheet-id', 'TabName')->all();
```

### Switching Sheets (Tabs) at Runtime

[](#switching-sheets-tabs-at-runtime)

```
$sheet = GoogleSheets::connection('default');

$sheet1Data = $sheet->sheet('Sheet1')->all();
$sheet2Data = $sheet->sheet('Sheet2')->all();
```

### Sheet / Tab Management

[](#sheet--tab-management)

```
// List all sheet tabs in a spreadsheet
$tabs = GoogleSheets::listSheets();   // ['Sheet1', 'Users', 'Reports']

// Check if a tab exists
GoogleSheets::sheetExists('Users');   // true

// Create a new tab
GoogleSheets::createSheet('Archive');

// Duplicate an existing tab
GoogleSheets::duplicateSheet('Sheet1', 'Sheet1 Copy');

// Delete a tab
GoogleSheets::deleteSheet('Archive');
```

### Caching

[](#caching)

Enable caching in config or at runtime to reduce API calls:

```
// In config/google-sheets.php
'cache' => [
    'enabled' => true,
    'store'   => 'redis',
    'ttl'     => 300,  // seconds
    'prefix'  => 'google_sheets_',
],

// At runtime
$rows = GoogleSheets::enableCache(600)->all();
$rows = GoogleSheets::disableCache()->all();
```

### Chunked Processing

[](#chunked-processing)

```
GoogleSheets::chunk(100, function ($chunk) {
    foreach ($chunk as $row) {
        // process each row
    }
});
```

### Spreadsheet Metadata

[](#spreadsheet-metadata)

```
$title = GoogleSheets::getTitle();
$id    = GoogleSheets::getSpreadsheetId();
```

### Dependency Injection

[](#dependency-injection)

```
use Olamilekan\GoogleSheets\GoogleSheetsManager;

class UserImportService
{
    public function __construct(
        protected GoogleSheetsManager $sheets
    ) {}

    public function import(): void
    {
        $rows = $this->sheets->connection('users')->all();

        foreach ($rows as $row) {
            User::updateOrCreate(
                ['email' => $row['email']],
                ['name' => $row['name']]
            );
        }
    }
}
```

---

API Reference
-------------

[](#api-reference)

### `GoogleSheetsManager`

[](#googlesheetsmanager)

MethodDescription`connection(?string $name)`Get a named connection (lazy-loaded &amp; cached)`make(string $spreadsheetId, string $sheet)`Create an ad-hoc sheet instance`getDefaultConnection()`Get the default connection name`purge(?string $name)`Remove a resolved connection`reconnect(?string $name)`Purge and re-resolve a connection### `Sheet`

[](#sheet)

MethodReturnsDescription`spreadsheet(string $id)``static`Override the spreadsheet ID`sheet(string $name)``static`Switch to a different tab`range(string $range)``static`Set A1 range for the next operation`get()``Collection`Read rows (headers mapped)`all()``Collection`Read all rows from the sheet`first()``?array`First data row`last()``?array`Last data row`headers()``array`Column headers (row 1)`find(col, val)``Collection`Filter rows by column value`where(col, op, val)``Collection`Filter with comparison operators`chunk(size, cb)``void`Process rows in chunks`append(array $rows)``int`Append rows (returns row count)`update(array $rows)``int`Update range (returns row count)`batchUpdate(array $data)``int`Update multiple ranges`clear()``bool`Clear values in range`createSheet(string)``static`Add a new tab`deleteSheet(string)``bool`Remove a tab`duplicateSheet(src, new)``static`Copy a tab`listSheets()``array`List all tab names`sheetExists(string)``bool`Check if a tab exists`withHeaders()``static`Map first row as keys (default)`withoutHeaders()``static`Return raw arrays`enableCache(?int $ttl)``static`Enable caching`disableCache()``static`Disable caching---

Environment Variables
---------------------

[](#environment-variables)

VariableDefaultDescription`GOOGLE_SHEETS_CREDENTIALS_PATH``storage/app/google/service-account.json`Path to credentials`GOOGLE_SHEETS_DEFAULT_CONNECTION``default`Default connection name`GOOGLE_SHEETS_SPREADSHEET_ID`—Spreadsheet ID for default connection`GOOGLE_SHEETS_APPLICATION_NAME``Laravel Google Sheets`App name for API requests`GOOGLE_SHEETS_CACHE_ENABLED``false`Enable response caching`GOOGLE_SHEETS_CACHE_STORE``null` (default driver)Cache store to use`GOOGLE_SHEETS_CACHE_TTL``300`Cache lifetime in seconds`GOOGLE_SHEETS_VALUE_RENDER``FORMATTED_VALUE`Value render option`GOOGLE_SHEETS_VALUE_INPUT``USER_ENTERED`Value input optionLicense
-------

[](#license)

MIT

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

45d ago

### Community

Maintainers

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

---

Top Contributors

[![oluwatosinolamilekan](https://avatars.githubusercontent.com/u/29930457?v=4)](https://github.com/oluwatosinolamilekan "oluwatosinolamilekan (1 commits)")

---

Tags

laravelspreadsheetgoogle apigoogle-sheets

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[barryvdh/laravel-dompdf

A DOMPDF Wrapper for Laravel

7.3k87.6M278](/packages/barryvdh-laravel-dompdf)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[rap2hpoutre/fast-excel

Fast Excel import/export for Laravel

2.3k24.9M47](/packages/rap2hpoutre-fast-excel)[elibyy/tcpdf-laravel

tcpdf support for Laravel 6, 7, 8, 9, 10, 11

3542.7M5](/packages/elibyy-tcpdf-laravel)[avadim/fast-excel-laravel

Lightweight and very fast XLSX Excel Spreadsheet Export/Import for Laravel

4146.7k1](/packages/avadim-fast-excel-laravel)

PHPackages © 2026

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