A simple Laravel package to create beautiful collection data from Google Sheets URL.
<?php
use namespace Fathilarham\GsheetsCollection;
// GsheetsCollection::get($url)->get($sheet = 1);
$url = 'https://docs.google.com/spreadsheets/d/1zQIz2xmAGjsvlDhECrvMxbnMmjmLhuWWIOYn2dar18M/edit?usp=sharing';
$data = GsheetsCollection::url($url)->get();
$ composer require fathilarhm/google-sheets-collection
{
"require": {
"fathilarhm/google-sheets-collection": "^1.0"
}
}
<?php
require 'vendor/autoload.php';
use Fathilarham\GsheetsCollection;
$url = 'https://docs.google.com/spreadsheets/d/1zQIz2xmAGjsvlDhECrvMxbnMmjmLhuWWIOYn2dar18M/edit?usp=sharing';
$data = GsheetsCollection::url($url)->get();
After installing this package to your Laravel project, you can follow this step :
- Create new Google Spreadsheet.
- Publish your Spreadsheet to the web (click 'Publish to the web' action in 'File' menu).
- Share your Spreadsheet and make it visible for public. Dont forget to copy the url.
- Place your url to this function parameter
GsheetsCollection::url($url);
- Get the data collection
GsheetsCollection::url(...)->get();
- If you want to take data from another sheet, you can add your sheet number to the second parameter of the function
GsheetsCollection::url(...)->get($sheet = 1);
- The result of
$data
would be :
[
{
"id": "1",
"code": "JT-001",
"origin": "Pontianak",
"destination": "Jakarta",
"time": "3/4/2020 8:00:00"
},
{
"id": "2",
"code": "SF-002",
"origin": "Jakarta",
"destination": "San Francisco",
"time": "13/8/2020 9:00:00"
}
]
To report a security vulnerability, please send an email to fathil.arham@gmail.com. I will coordinate the fix and disclosure.