fnsc/laravel-google-drive

Filesystem adapter for Google Drive

Maintainers

Package info

github.com/fnsc/laravel-google-drive

pkg:composer/fnsc/laravel-google-drive

Statistics

Installs: 211

Dependents: 0

Suggesters: 0

Stars: 7

Open Issues: 2

1.3.0 2026-03-13 03:25 UTC

This package is auto-updated.

Last update: 2026-03-13 04:10:13 UTC


README

Tests Status

A Laravel package to upload, download, and delete files on Google Drive using a service account.

Requirements

  • PHP ^8.2
  • Laravel ^10.0

Installation

composer require fnsc/laravel-google-drive

Publish the config file:

php artisan vendor:publish --provider="LaravelGoogleDrive\ServiceProvider"

Setup

1. Create a Google Service Account

Go to Google Cloud Console → Credentials, create a Service Account, and download the generated JSON key file.

Add the file to your project (e.g. storage/app/service-account.json) and never commit it to git.

2. Share the Google Drive folder

Open the target folder in Google Drive, click Share, and add the client_email from the JSON file with Editor access.

3. Configure environment variables

Add the following to your .env file:

GOOGLE_APPLICATION_CREDENTIALS=storage/app/service-account.json
GOOGLE_DRIVE_FOLDER_ID=your_folder_id_here

GOOGLE_APPLICATION_CREDENTIALS is the path to the JSON key file relative to the project root. GOOGLE_DRIVE_FOLDER_ID is the ID found in the Google Drive folder URL: https://drive.google.com/drive/folders/<FOLDER_ID>.

Usage

Inject LaravelGoogleDrive\GoogleDrive into your controller or route closure.

Upload a file

use LaravelGoogleDrive\GoogleDrive;
use Illuminate\Http\Request;

Route::post('/upload', function (Request $request, GoogleDrive $drive) {
    $result = $drive->upload($request->file('file'));

    return [
        'file_id'   => $result->getFileId(),
        'file_name' => $result->getFileName(),
        'folder_id' => $result->getFolderId(),
    ];
});

To upload to a specific folder instead of the default one, pass the folder ID as the second argument:

$drive->upload($request->file('file'), 'your_folder_id');

Upload multiple files

$results = $drive->uploadMany($request->file('files'));

Download a file

use Illuminate\Http\Response;

Route::get('/download', function (GoogleDrive $drive) {
    $file = $drive->get('filename.pdf', 'google_drive_file_id');

    return new Response($file->getContent(), 200, [
        'Content-Type'        => $file->getMimeType(),
        'Content-Disposition' => 'attachment; filename=' . $file->getName(),
    ]);
});

Delete a file

$deleted = $drive->delete('google_drive_file_id'); // returns bool

License

This package is free software distributed under the terms of the MIT license.