scryba/laravel-google-drive-filesystem

Google Drive filesystem adapter for Laravel (10, 11, 12)

v1.1.3 2025-08-05 09:19 UTC

This package is auto-updated.

Last update: 2025-08-05 09:23:37 UTC


README

Latest Version on Packagist Total Downloads License PHP Version Laravel Version

A robust Google Drive filesystem adapter for Laravel that provides seamless integration with Google Drive as a storage disk. Features configurable debug logging, automatic folder creation, and full Laravel Filesystem API compatibility.

✨ Features

  • 🚀 Full Laravel Filesystem API Support - Use Google Drive like any other Laravel disk
  • 🔧 Configurable Debug Logging - Control debug output in production environments
  • 📁 Automatic Folder Creation - Folders are created automatically when needed
  • 🔐 Secure Authentication - Support for both access tokens and refresh tokens
  • 📊 Metadata Support - File sizes, modification times, and MIME types
  • 🛡️ Production Ready - Proper error handling and logging configuration
  • 📚 Comprehensive Documentation - Detailed setup and usage guides

📋 Requirements

  • PHP 8.1 or higher
  • Laravel 10.x, 11.x, or 12.x
  • Google Cloud Platform project with Drive API enabled

🚀 Quick Installation

Install via Composer:

composer require scryba/laravel-google-drive-filesystem

For advanced installation and VCS/development setup, see docs/INSTALLATION.md.

⚙️ Quick Configuration

Publish the config file and set up your .env:

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

Add your Google Drive credentials to your .env file. For a detailed step-by-step guide, see docs/GETTING-TOKENS.md.

🔑 Environment Variables

# Google Drive API Credentials
GOOGLE_DRIVE_CLIENT_ID=your-client-id
GOOGLE_DRIVE_CLIENT_SECRET=your-client-secret
GOOGLE_DRIVE_ACCESS_TOKEN=your-access-token
GOOGLE_DRIVE_REFRESH_TOKEN=your-refresh-token
GOOGLE_DRIVE_FOLDER_ID=your-folder-id

# Debug Logging (optional)
GOOGLE_DRIVE_DEBUG=false
GOOGLE_DRIVE_LOG_PAYLOAD=false

Debug Logging Options

The debug logging options default to APP_DEBUG but can be overridden:

  • GOOGLE_DRIVE_DEBUG: Enable detailed debug logging for operations (defaults to APP_DEBUG)
  • GOOGLE_DRIVE_LOG_PAYLOAD: Enable logging of HTTP payloads and detailed operation info (defaults to APP_DEBUG)

Production Tip: Set both debug options to false in production to prevent unnecessary log output.

📖 Usage

After configuring, you can use the Google Drive disk in your Laravel application like this:

use Illuminate\Support\Facades\Storage;

// Store a file
Storage::disk('google')->put('example.txt', 'Hello, Google Drive!');

// Retrieve a file
$content = Storage::disk('google')->get('example.txt');

// List files in a directory
$files = Storage::disk('google')->files('/');

// Delete a file
Storage::disk('google')->delete('example.txt');

// Check if file exists
if (Storage::disk('google')->exists('example.txt')) {
    // File exists
}

// Get file size
$size = Storage::disk('google')->size('example.txt');

// Get last modified time
$modified = Storage::disk('google')->lastModified('example.txt');

🗂️ Working with Folders

// Create a directory (folders are created automatically when uploading files)
Storage::disk('google')->makeDirectory('uploads/images');

// List directories
$directories = Storage::disk('google')->directories('/');

// List all contents (files and folders)
$contents = Storage::disk('google')->allFiles('/');

// Delete a directory and all its contents
Storage::disk('google')->deleteDirectory('uploads/images');

For advanced usage and more examples, see docs/USAGE.md.

🔧 Laravel Compatibility

  • Laravel: 10.x, 11.x, 12.x
  • PHP: 8.1 or higher
  • Google API Client: ^2.15
  • Flysystem: ^3.0

📝 License

This package is open-sourced software licensed under the MIT license.

🤝 Support

📚 Documentation