grosv/eloquent-sheets 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

grosv/eloquent-sheets

Composer 安装命令:

composer require grosv/eloquent-sheets

包简介

Eloquent models backed by Google Sheets

README 文档

README

A package that lets you lay Eloquent on top of a Google Sheet.

Latest Version on Packagist StyleCI Build Status

This package provides an Eloquent model that sits on top of a Google Sheet. You can use a heading row that holds the name of your columns. This defaults to row 1 (the top row) but it can be any row in the sheet. Or you can define an array of headings in your model. If you choose not to have a primary key column in your spreadsheet, each column will get an id (or whatever you're calling your primary key column in your model) auto-incremented.

When you use this package, an initial invocation of the model will read the sheet and store each row as a record in a table inside a file-based sqlite database. Subsequent invocations of the model use that sqlite database so changes to the spreadsheet won't be reflected in the database. However, there are two ways that you can invalidate the sqlite cache and cause it to be recreated:

  1. You can call the invalidateCache() method on the model with something like like YourGoogleSheetModel::first()->invalidateCache()

  2. A macro that you can attach to your Google sheet. The macro listens for edits within the sheet and when one happens, it sends a request to a route provided by this package that deletes the sqlite database forcing a fresh load the next time the model is used.

Installation

composer require grosv/eloquent-sheets

Configuration

This package relies on revolution/laravel-google-sheets. You must handle the configuration for that package and its dependencies for this package to work. Follow the instructions in their readme (though you can skip the composer require bit because I do that already in here).

Usage

Consider the following Google Sheet. We want to lay an Eloquent model on top of it.

Screen Shot 2020-03-03 at 3 02 15 PM

php artisan make:sheet-model

Step 1 - Enter the full path to the directory where you want to create the model file (defaults to app_path()):

Screen Shot 2020-03-11 at 4 48 48 PM

Step 2 - Enter the name you want to use for your model class:

Screen Shot 2020-03-03 at 3 11 10 PM

Step 3 - Paste the edit url of your Google Sheet from the browser address bar:

Screen Shot 2020-03-03 at 3 13 33 PM

Step 4 - Confirm that the path and full classname look right:

Screen Shot 2020-03-03 at 3 14 47 PM

Step 5 - And you will receive the template of a macro that you can attach to your sheet that will tell your site that the sheet has changed so a new cache has to be built.

Screen Shot 2020-03-03 at 3 20 58 PM

You can use something like this to enable the macro generated on your sheet as an installable trigger:

function createSpreadsheetOpenTrigger() {
  var ss = SpreadsheetApp.getActive();
  ScriptApp.newTrigger('onEdit')
      .forSpreadsheet(ss)
      .onEdit()
      .create();
}

The Resulting Model Class

use Grosv\EloquentSheets\SheetModel;

class YourGoogleSheetsModel extends SheetModel
{
    protected $spreadsheetId = '1HxNqqLtc614UVLoTLEItfvcdcOm3URBEM2Zkr36Z1rE'; // The id of the spreadsheet
    protected $sheetId = '0'; // The id of the sheet within the spreadsheet (gid=xxxxx on the URL)
    protected $headerRow = '1'; // The row containing the names of your columns (eg. id, name, email, phone)
}

This model can do your basic Eloquent model stuff because it really is an Eloquent model. Though it's currently limited to read / list methods. Update and insert don't currently work because you do those things by editing your spreadsheet.

What's Missing

Eventually I'd like to add insert and update methods that will let you append rows to your spreadsheet and edit existing rows. I already have the most important part done... a method to invalidate the cache when we update or insert. Now I just need the update and insert methods.

Acknowledgements

This package wouldn't be possible without Sushi by Caleb Porzio. If you're not sponsoring him on GitHub you should.

grosv/eloquent-sheets 适用场景与选型建议

grosv/eloquent-sheets 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.38k 次下载、GitHub Stars 达 289, 最近一次更新时间为 2020 年 03 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 grosv/eloquent-sheets 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 grosv/eloquent-sheets 我们能提供哪些服务?
定制开发 / 二次开发

基于 grosv/eloquent-sheets 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 289
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 289
  • Watchers: 10
  • Forks: 15
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-02