ibnuhalimm/laravel-google-sheet

Google Sheet API wrapper for Laravel

v1.2.1 2022-04-23 03:47 UTC

This package is auto-updated.

Last update: 2024-12-23 09:28:37 UTC


README

Latest Version on Packagist Total Downloads

Google Sheet API Wrapper for Laravel. Easiest way to interact with your sheet.

Contents

Requirements

  1. Create a Google Cloud project. If you want to use your existing project, you can jump to the next step.
  2. Create Service Acount Credentials on Google Developer Console and share your Google Sheet file to these service account email.
  3. Place your downloaded service account json file to storage/app/google-sheet/ folder, then rename these file to credentials.json.
  4. Enable Google Sheet API on Google Workspace APIs.

Installation

You can install the package via composer:

composer require ibnuhalimm/laravel-google-sheet

Optionally, you can publish the config file of this package with this command:

php artisan vendor:publish --provider="Ibnuhalimm\LaravelGoogleSheet\GoogleSheetServiceProvider"

or by mention the config tag

php artisan vendor:publish --tag=google-sheet-config

Usage

Fetch the data

You can use GoogleSheet facade (the alias or class itself).

use GoogleSheet;

$spreadSheetId = '1cyUalLbuw_TpAIgkf76JcU-BbsYCSwtVqJuf_gCNzYA';
$sheetName = 'Class Data';
$cellRange = 'A1:E5';

GoogleSheet::useDocument($spreadSheetId)->fetchData($sheetName, $cellRange);

This method will returns the subset of array data

=> [
     [
       "Student Name",
       "Gender",
       "Class Level",
       "Home State",
       "Major",
     ],
     [
       "Alexandra",
       "Female",
       "4. Senior",
       "CA",
       "English",
     ],
    ...

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email ibnuhalim@pm.me instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.