funnydevjsc/google-drive-laravel-integrate

Laravel package for Google Drive management

1.0.2 2025-03-21 17:31 UTC

This package is auto-updated.

Last update: 2025-03-21 17:32:09 UTC


README

The free Laravel package to help you manage your Google Drive

Use Cases

  • CRUD files and folders on your Google Drive
  • Upload and download without normal Google Drive exceeded limits

Features

  • Dynamic Google Service credentials from config/google-service.php
  • Dynamic Google Drive properties from config/google-drive.php
  • Easy to CRUD files and folders on your Google Drive with a simple line code

Know issues

  • This package uses the latest official SDK, libraries and methods from Google then it might be large (around 30mb for dependency package google/apiclient) for shared hosting.
  • Please consider your server's environment before using this package.
  • However, we still recommend that you follow the latest writing style for Google libraries to ensure safety, compliance, CI/CD and most importantly if you are using services

Requirements

  • PHP: 8.1 or higher
  • Laravel 9.0 or higher

Quick Start

If you prefer to install this package into your own Laravel application, please follow the installation steps below

Installation

Step 1. Install a Laravel project if you don't have one already

https://laravel.com/docs/installation

Step 2. Require the current package using composer:

composer require funnydevjsc/google-drive-laravel-integrate

Step 3. Create a Google Service credentials:

Step 4. Publish the controller file and config file

php artisan vendor:publish --provider="FunnyDev\GoogleDrive\GoogleDriveServiceProvider" --tag="funnydev-google-drive"

If publishing files fails, please create corresponding files at the path config/google-drive.php from this package.

Step 5. Update the various config settings in the published config file:

  • After publishing the package assets a configuration file will be located at config/google-drive.php.
  • Find your Google Drive parent folder ID and fill into config/google-drive.php file like this (your files and folders might be uploaded and managed within this parent folder):

Testing

use FunnyDev\GoogleDrive\GoogleDriveSdk;

class TestDrive
{
    /**
     * Handle the event.
     * @throws \Exception
     */
    public function handle(): void
    {
        $drive = new GoogleDriveSdk();
        
        $folderId = $drive->createFolder('test', config('google-drive.parent_folder_id'));
        
        $fileId = $drive->uploadFile(
            $folderId,
            'file_uploaded.txt',
            file_get_contents(storage_path('file.txt')),
            'text/plain'
        );
        
        $file = $drive->downloadFile($fileId);
        file_put_contents(storage_path('file_downloaded.txt'), $file);
        
        if ($drive->deleteResource($fileId)) {
            echo 'Deleted file';
        }
    }
}

Feedback

Respect us in the Laravel Việt Nam

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email contact@funnydev.vn or use the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.