首选的 PHP IDE,对 Laravel 及其生态系统提供广泛的开箱即用支持。

Use a Google Sheet as Your Laravel Database with the Google Sheets Database Driver

最后更新于 经过

Use a Google Sheet as Your Laravel Database with the Google Sheets Database Driver image

Laravel Google Sheets Database Driver 经过 AmazingBV registers a custom google-sheets connection, letting Eloquent, the query builder, and migrations read and write directly to a Google Sheet.

The mental model is simple: the spreadsheet is the database, each tab is a table, and the header row defines the columns. The rest is plumbing the package handles for you.

When this makes sense

This is not a MySQL replacement, and the package's author is upfront about that. The intended audience is teams with modest data needs: small back-office apps, prototypes, internal tools, and the kind of light integrations where reaching for MySQL or PostgreSQL feels like overkill. The clearest sign that this package is a fit is when the spreadsheet itself is already part of how the team works, non-developers want to look at or edit the data directly, the row counts stay modest, and you don't need the database to enforce relational rules for you.

If you need transactions, foreign keys, database-level constraints, or high write throughput, this is not the right pick.

Getting set up

After installing with Composer:

作曲家 要求 amazingbv/laravel-google-sheets-database-driver

You'll need a service account JSON key from Google Cloud. The short version: create or pick a Google Cloud project, enable the Google Sheets API, create a service account, and download its JSON key. The package's GitHub repo walks through these steps in more detail.

With the key in hand, point Laravel at your spreadsheet ID and the credentials file in your .env :

数据库连接 = google-sheets
数据库 = your-google-spreadsheet-id
GOOGLE_SHEETS_CREDENTIALS_PATH = /absolute/path/to/service-account.json

The service account's client_email (from the JSON key) needs Editor access to the spreadsheet. Then a one-time install command prepares the internal tabs the driver uses:

php 工匠 sheets:install

A small example

Imagine a tiny app for tracking RSVPs to a community meetup. The migration looks like a normal Laravel migration:

架构 :: 联系 'google-sheets' -> 创造 'rsvps' , 功能 蓝图 $table) {
$表 -> ID ();
$表 -> 细绳 '姓名' (英文):
$表 -> 细绳 '电子邮件' (英文):
$表 -> 布尔值 'attending' -> 默认 真的 (英文):
$表 -> 时间戳 ();
});

Run it with php artisan migrate --database=google-sheets 以及 rsvps tab appears in the spreadsheet, headers and all.

The model itself doesn't require anything unusual:

班级 Rsvp 延伸 模型
{
受保护 $连接 = 'google-sheets' ;
受保护 $守卫 = [];
受保护 类型 = [ 'attending' => '布尔值' ];
}

From there, the usual calls just work:

Rsvp :: 创造 ([
'姓名' => 'Ada Lovelace' ,
'电子邮件' => 'ada@example.com' ,
'attending' => 真的 ,
]);
$已确认 = Rsvp :: 在哪里 'attending' , 真的
-> orderBy 'created_at'
-> 得到 ();

Every write shows up in the sheet immediately, which is the whole point: the event organizer can sort, filter, and tweak the data in Google Sheets while the Laravel app keeps reading the same rows.

What you can and can't query

The driver supports a working subset of the query API rather than full SQL. You get where , whereIn , whereNull , whereLike , orderBy , limit , offset , the usual aggregates ( count , sum , avg , and friends), and a simple in-memory inner join.

What you don't get: raw SQL, groupBy , having , unions, and real transactions. Laravel's DB::transaction() calls are accepted as no-ops, which keeps queue workers and framework internals happy but offers no rollback.

Migrations follow the same forgiving approach. Calls like ->unique() , ->index() , 和 ->foreignId()->constrained() don't fail, but Google Sheets won't enforce them either. If you depend on those guarantees, enforce them in application code.

Living with API quotas

Google Sheets has tight per-minute API quotas, so the driver puts a few guardrails in place: in-process read caching, configurable per-minute throttles, exponential-backoff retries on quota errors, and an optional Laravel cache store (file, redis, etc.) for further reduction in API calls. All of those knobs are tunable from .env , and the author includes a short troubleshooting list for when you start seeing quota errors.

The "Database Index" tab

One small detail worth calling out: the package keeps a visible Database Index tab as the first tab in the spreadsheet, with linked rows pointing at each table tab. It is a nice quality-of-life feature for anyone opening the sheet directly, and it makes the spreadsheet feel less like a black box and more like something a non-developer can navigate.

尝试一下

To learn more and view the source code, head over to the package's GitHub 存储库

Yannick Lyn Fatt 的照片

Laravel News 的特约撰稿人和全栈 Web 开发人员。

归档于:
立方体

Laravel 时事通讯

加入超过 4 万名开发者的行列,不错过任何新的技巧、教程等内容。

图像
了解软科技

以每小时 20 美元的价格聘请具备人工智能专业知识的 Laravel 开发人员。48 小时内即可开始工作。

访问 Acquaint Softtech
SerpApi logo

SerpApi

Access real-time search engine results through a simple API—no more scraping headaches! Use it for AI applications, SEO tools, product research, travel information, and more

SerpApi
PhpStorm 标志

PhpStorm

首选的 PHP IDE,对 Laravel 及其生态系统提供广泛的开箱即用支持。

PhpStorm
鱼叉:新一代时间跟踪和发票标志

Harpoon:新一代时间跟踪和发票系统

新一代时间跟踪和计费软件,帮助您的机构规划和预测盈利的未来。

Harpoon:新一代时间跟踪和发票系统
几天内即可获得 Laravel 代码审查徽标的专家指导

几天内即可获得 Laravel 代码审查方面的专家指导

专家级代码审查!两位拥有 10 年以上 Laravel 开发经验的开发者将为您提供清晰、实用的反馈,帮助团队构建更优质的应用程序。

几天内即可获得 Laravel 代码审查方面的专家指导
SaaSykit:Laravel SaaS 入门套件徽标

SaaSykit:Laravel SaaS 入门套件

SaaSykit 是一个多租户 Laravel SaaS 入门套件,包含运行现代 SaaS 所需的所有功能,例如支付、美观的结账界面、管理面板、用户仪表盘、身份验证、现成组件、统计数据、博客、文档等等。

SaaSykit:Laravel SaaS 入门套件
Lucky Media 标志

幸运传媒

Get Lucky Now——拥有十余年经验的 Laravel 开发理想之选!

幸运传媒
Laravel Cloud 标志

Laravel 云

轻松创建和管理服务器,并在几秒钟内部署 Laravel 应用程序。

Laravel 云
Tinkerwell 徽标

廷克威尔

Laravel 开发者必备的代码运行器。可在本地和生产环境中体验 AI、自动补全和即时反馈功能。

廷克威尔
Kirschbaum 标志

樱桃树

提供创新和稳定性,确保您的Web应用程序取得成功。

樱桃树
了解 Softtech 的标志

了解软科技

Acquaint Softtech 提供 AI 就绪的 Laravel 开发人员,48 小时内即可上手,每月费用为 3000 美元,没有冗长的销售流程,并提供 100% 退款保证。

了解软科技
Shift 标志

转移

还在运行旧版本的 Laravel?立即实现 Laravel 自动升级和代码现代化,让您的应用程序保持最新状态。

转移
Drag-and-Drop Sorting for Eloquent Models with Reorderable for Laravel image

Drag-and-Drop Sorting for Eloquent Models with Reorderable for Laravel

阅读文章
Ship AI with Laravel: Real-Time Streaming Chat UI with Livewire image

Ship AI with Laravel: Real-Time Streaming Chat UI with Livewire

阅读文章
Frontend Nation 2026 Returns June 3-4 with Laravel in the Lineup image

Frontend Nation 2026 Returns June 3-4 with Laravel in the Lineup

阅读文章
Larapanda: A Type-Safe Lightpanda Browser SDK for Laravel image

Larapanda: A Type-Safe Lightpanda Browser SDK for Laravel

阅读文章
Generate HTML Password Rules Attribute in Laravel 13.9.0 image

Generate HTML Password Rules Attribute in Laravel 13.9.0

阅读文章
DHH Joins Laravel Live Denmark 2026 for Fireside Chat with Taylor Otwell image

DHH Joins Laravel Live Denmark 2026 for Fireside Chat with Taylor Otwell

阅读文章