The enflow/laravel-excel-exporter package provides an easy way to push Laravel Excel exports to Google Sheets and Google BigQuery.
Common use-cases include exporting data with Laravel Excel in your application while periodically syncing that same export to a Google Sheet or a Google BigQuery table.
You can install the package via Composer:
composer require enflow/laravel-excel-exporterThis package uses the Google API PHP Client under the hood. You will need a Google Cloud project with the correct APIs enabled and a Service Account JSON key.
Create a Service Account JSON key:
- Go to the Google Cloud Console
- Create a new project or select an existing project
- Go to
APIs & Services>Credentials - Click
Create Credentials>Service account - Enable the APIs you need in the project:
- For Google Sheets:
Google Sheets API - For Google BigQuery:
BigQuery API
- For Google Sheets:
- Fill in the required fields and click
Create - Select the created service account and click
Add key>Create new key - Select
JSONand clickCreate - The JSON file will be downloaded to your computer
- Store the downloaded JSON file securely. We recommend
storage/secrets/google-service-account.json.
Publish the config file:
php artisan vendor:publish --tag="laravel-excel-exporter-config"Register your exports in the exports array:
'exports' => [
// key => Export class (must be resolvable from the container)
'teams' => \App\Exports\TeamsExport::class,
],You can validate an export by running the push command interactively:
php artisan excel-exporter:pushTo periodically push all configured exports to their destinations, schedule the PushAll command. This will send all defined exports to their configured exporter:
use Enflow\LaravelExcelExporter\Commands\PushAll;
$schedule->command(PushAll::class)->dailyAt('03:00')->environments('production');This package supports two exporters:
Implement the ExportableToGoogleSheet interface on your export class and return the target Spreadsheet ID:
use Enflow\LaravelExcelExporter\Exporters\GoogleSheet\ExportableToGoogleSheet;
class TeamsExport implements ExportableToGoogleSheet
{
public function googleSpreadsheetId(): string
{
return 'your-spreadsheet-id';
}
// ... other export methods
}Set the project and dataset in the package config. Then implement ExportableToGoogleBigQuery on your export class and specify the table and schema:
use Enflow\LaravelExcelExporter\Exporters\GoogleBigQuery\ExportableToGoogleBigQuery;
class TeamsExport implements ExportableToGoogleBigQuery
{
public function googleBigQueryTableId(): string
{
return 'teams';
}
public function googleBigQuerySchema(): array
{
// column => BigQuery type (e.g. STRING, INT64, FLOAT64, BOOL, TIMESTAMP, DATE)
return [
'id' => 'INT64',
'name' => 'STRING',
'created_at' => 'TIMESTAMP',
];
}
}Notes:
- Ensure the dataset exists in your BigQuery project. The table will be created or replaced automatically based on the schema you provide.
- Configure
project_id,dataset_id, and service account credentials inconfig/excel-exporter.php.
Prefer a single dataset with multiple tables per project. Each export class can target a different table via googleBigQueryTableId() while sharing the configured dataset.
excel-exporter:push— interactively push one configured export (or via--export=key).excel-exporter:push-all— push all configured exports.
Excel exports can be memory intensive. You may set memory_limit in config/excel-exporter.php for the duration of the push.
$ composer testPlease see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Enflow is a digital creative agency based in Alphen aan den Rijn, Netherlands. We specialize in developing web applications, mobile applications and websites. You can find more info on our website.
The MIT License (MIT). Please see License File for more information.