fnsc / laravel-google-drive
Filesystem adapter for Google Drive
Requires
- php: ^8.2
- google/apiclient: ^2.13
- illuminate/config: ^10.0|^11.0|^12.0
- illuminate/console: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- leroy-merlin-br/coding-standard: v3.1.0
- mockery/mockery: ^1.6.2
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpro/grumphp: ^v2.0.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.2
- rector/rector: ^0.17
This package is auto-updated.
Last update: 2026-03-13 04:10:13 UTC
README
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.