PHPackages                             ikhsant/laravel-google-shared-drive - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ikhsant/laravel-google-shared-drive

ActiveLibrary[API Development](/categories/api)

ikhsant/laravel-google-shared-drive
===================================

Google Shared Drive client integration for Laravel.

v1.0.0(1mo ago)017↓90%MITPHPPHP ^8.2|^8.3|^8.4

Since Jun 3Pushed 1mo agoCompare

[ Source](https://github.com/ikhsant/laravel-google-shared-drive)[ Packagist](https://packagist.org/packages/ikhsant/laravel-google-shared-drive)[ RSS](/packages/ikhsant-laravel-google-shared-drive/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

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
--------

[](#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
------------

[](#installation)

Install the package via Composer:

```
composer require ikhsant/laravel-google-shared-drive
```

### Run Migrations

[](#run-migrations)

The package includes a migration for the `media` table. Run your migrations to create it:

```
php artisan migrate
```

Configuration
-------------

[](#configuration)

Publish the config file:

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

This will create a `config/google-shared-drive.php` file:

```
use Ikhsant\LaravelGoogleSharedDrive\Models\Media;

return [
    'service_account_json' => env('GOOGLE_DRIVE_SERVICE_ACCOUNT_JSON', 'google/service-account.json'),
    'root_folder_id' => env('GOOGLE_DRIVE_ROOT_FOLDER_ID'),

    /*
     * The model that should be used for storing media records.
     */
    'media_model' => Media::class,

    /*
     * The default disk name stored in the media table.
     */
    'disk' => 'google_drive',
];
```

Ensure you have your Service Account JSON placed under `storage/app/` (e.g., `storage/app/google/service-account.json`) and configure your `.env`:

```
GOOGLE_DRIVE_SERVICE_ACCOUNT_JSON=google/service-account.json
GOOGLE_DRIVE_ROOT_FOLDER_ID=your-root-folder-or-shared-drive-id
```

Google Cloud &amp; Shared Drive Setup Guide
-------------------------------------------

[](#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`

[](#1-how-to-obtain-service-accountjson)

1. Go to the [Google Cloud Console](https://console.cloud.google.com/).
2. Create a new project or select an existing one.
3. Enable the **Google Drive API**:
    - Navigate to **APIs &amp; Services &gt; Library**.
    - Search for "Google Drive API" and click **Enable**.
4. Create a **Service Account**:
    - Navigate to **APIs &amp; Services &gt; Credentials**.
    - Click **Create Credentials** and choose **Service Account**.
    - Enter service account details and click **Create and Continue**, then **Done**.
5. Create and download the JSON key:
    - Click on the newly created service account from the list.
    - Go to the **Keys** tab.
    - Click **Add Key &gt; Create new key**.
    - Select **JSON** and click **Create**.
    - A JSON file will be downloaded. Rename it (e.g. `service-account.json`) and place it under `storage/app/google/service-account.json` (or use an absolute path).

### 2. How to Setup Google Drive / Shared Drive Access

[](#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:

1. Open the downloaded JSON credentials file.
2. Find and copy the `"client_email"` value (looks like `service-account-name@project-id.iam.gserviceaccount.com`).
3. Open Google Drive in your browser.
4. Right-click the folder or Shared Drive you want to use as the root, and select **Share** (or **Manage members** for Shared Drives).
5. Paste the service account's client email and assign it the **Editor** (or **Content Manager** / **Contributor**) role.
6. Copy the Folder ID from the browser URL (e.g. in `https://drive.google.com/drive/folders/1aBcDeFgHiJkLmNoPqRsTuVwXyZ`, the folder ID is `1aBcDeFgHiJkLmNoPqRsTuVwXyZ`).
7. Add this folder ID into your `.env` file as `GOOGLE_DRIVE_ROOT_FOLDER_ID`.

---

Media Library Usage
-------------------

[](#media-library-usage)

### 1. Prepare Your Model

[](#1-prepare-your-model)

Add the `HasMedia` trait to your Eloquent model:

```
use Ikhsant\LaravelGoogleSharedDrive\Traits\HasMedia;
use Illuminate\Database\Eloquent\Model;

class Consultation extends Model
{
    use HasMedia;
}
```

### 2. Upload / Associate Media Fluently

[](#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()`:

```
// Upload a file to a nested folder 'consultations/docs', customize filename, and attach to 'attachments' collection
$media = $consultation->addMedia($request->file('file'))
    ->toFolder('consultations/docs')
    ->usingFileName('custom-name.pdf')
    ->toMediaCollection('attachments');
```

*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

[](#3-retrieve--download-media-contents)

Use the relation to get media and retrieve file contents directly:

```
$media = $consultation->media()->first();

// Get the raw file content from Google Drive
$contents = $media->contents();

return response($contents)
    ->header('Content-Type', $media->mime_type)
    ->header('Content-Disposition', 'attachment; filename="'.$media->file_name.'"');
```

### 4. Delete Media

[](#4-delete-media)

Deleting a media model automatically triggers the model event that deletes the corresponding file from Google Shared Drive:

```
$media->delete(); // This automatically calls GoogleSharedDrive::delete()
```

---

Low-Level API Usage (Facade)
----------------------------

[](#low-level-api-usage-facade)

For direct interactions with Google Shared Drive without database models, use the `GoogleSharedDrive` facade.

### Upload a File

[](#upload-a-file)

```
use Ikhsant\LaravelGoogleSharedDrive\Facades\GoogleSharedDrive;

$result = GoogleSharedDrive::upload($request->file('file'), 'custom/folder/path');

// Response:
// [
//     'file_id' => '...',
//     'file_name' => '...',
//     'mime_type' => '...',
//     'size' => 12345
// ]
```

### Download File Contents

[](#download-file-contents)

```
use Ikhsant\LaravelGoogleSharedDrive\Facades\GoogleSharedDrive;

$contents = GoogleSharedDrive::download($fileId);
```

### Delete a File

[](#delete-a-file)

```
use Ikhsant\LaravelGoogleSharedDrive\Facades\GoogleSharedDrive;

GoogleSharedDrive::delete($fileId);
```

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance91

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

52d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bea22c82ebd24349b874a871339fa3e659fd9156d410f8d48b9d6f77557b09a1?d=identicon)[ikhsant](/maintainers/ikhsant)

---

Top Contributors

[![ikhsant](https://avatars.githubusercontent.com/u/39888845?v=4)](https://github.com/ikhsant "ikhsant (6 commits)")

### Embed Badge

![Health badge](/badges/ikhsant-laravel-google-shared-drive/health.svg)

```
[![Health](https://phpackages.com/badges/ikhsant-laravel-google-shared-drive/health.svg)](https://phpackages.com/packages/ikhsant-laravel-google-shared-drive)
```

###  Alternatives

[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1235.9k21](/packages/fleetbase-core-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
