Download the PHP package ikhsant/laravel-google-shared-drive without Composer
On this page you can find all versions of the php package ikhsant/laravel-google-shared-drive. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ikhsant/laravel-google-shared-drive
More information about ikhsant/laravel-google-shared-drive
Files in ikhsant/laravel-google-shared-drive
Package laravel-google-shared-drive
Short Description Google Shared Drive client integration for Laravel.
License MIT
Informations about the package laravel-google-shared-drive
Laravel Google Shared Drive
An easy-to-use Laravel package to integrate Google Drive and Shared Drive APIs with minimal setup, featuring a Spatie-inspired Media Library helper for Eloquent models.
Features
- Simple upload, download, and delete operations on Google Shared Drive.
- Spatie-inspired fluent media attachments (
$model->addMedia($file)->toFolder('custom/path')->toMediaCollection()). - Automatic Google Drive file deletion via Eloquent model event listeners.
- Custom media model configuration.
- Clean Laravel Facade integration to minimize boilerplate code.
- Auto-discovery support.
Installation
Install the package via Composer:
Run Migrations
The package includes a migration for the media table. Run your migrations to create it:
Configuration
Publish the config file:
This will create a config/google-shared-drive.php file:
Ensure you have your Service Account JSON placed under storage/app/ (e.g., storage/app/google/service-account.json) and configure your .env:
Google Cloud & Shared Drive Setup Guide
To use this package, you need a Google Service Account credentials file (service-account.json) and a shared folder or Shared Drive.
1. How to obtain service-account.json
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Enable the Google Drive API:
- Navigate to APIs & Services > Library.
- Search for "Google Drive API" and click Enable.
- Create a Service Account:
- Navigate to APIs & Services > Credentials.
- Click Create Credentials and choose Service Account.
- Enter service account details and click Create and Continue, then Done.
- Create and download the JSON key:
- Click on the newly created service account from the list.
- Go to the Keys tab.
- Click Add Key > Create new key.
- Select JSON and click Create.
- A JSON file will be downloaded. Rename it (e.g.
service-account.json) and place it understorage/app/google/service-account.json(or use an absolute path).
2. How to Setup Google Drive / Shared Drive Access
For the service account to interact with your Google Drive folder, you must share the target folder with the service account:
- Open the downloaded JSON credentials file.
- Find and copy the
"client_email"value (looks like[email protected]). - Open Google Drive in your browser.
- Right-click the folder or Shared Drive you want to use as the root, and select Share (or Manage members for Shared Drives).
- Paste the service account's client email and assign it the Editor (or Content Manager / Contributor) role.
- Copy the Folder ID from the browser URL (e.g. in
https://drive.google.com/drive/folders/1aBcDeFgHiJkLmNoPqRsTuVwXyZ, the folder ID is1aBcDeFgHiJkLmNoPqRsTuVwXyZ). - Add this folder ID into your
.envfile asGOOGLE_DRIVE_ROOT_FOLDER_ID.
Media Library Usage
1. Prepare Your Model
Add the HasMedia trait to your Eloquent model:
2. Upload / Associate Media Fluently
You can upload a file and associate it with the model using the Spatie-inspired fluent API. You can specify a custom nested folder path on Google Drive via toFolder():
Note: Folder path lookup is fully optimized using Laravel's cache. If a folder is manually deleted from Drive, the package auto-detects and self-heals by recreating it.
3. Retrieve / Download Media Contents
Use the relation to get media and retrieve file contents directly:
4. Delete Media
Deleting a media model automatically triggers the model event that deletes the corresponding file from Google Shared Drive:
Low-Level API Usage (Facade)
For direct interactions with Google Shared Drive without database models, use the GoogleSharedDrive facade.
Upload a File
Download File Contents
Delete a File
All versions of laravel-google-shared-drive with dependencies
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
google/apiclient Version ^2.19