PHPackages                             kalprajsolutions/laravel-onedrive-filesystem - 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. [Database &amp; ORM](/categories/database)
4. /
5. kalprajsolutions/laravel-onedrive-filesystem

ActiveLibrary[Database &amp; ORM](/categories/database)

kalprajsolutions/laravel-onedrive-filesystem
============================================

OneDrive filesystem driver for Laravel using Microsoft Graph API

V1(4mo ago)1214↓75%MITPHPPHP ^8.1

Since Feb 6Pushed 3mo agoCompare

[ Source](https://github.com/kalprajsolutions/laravel-onedrive-filesystem)[ Packagist](https://packagist.org/packages/kalprajsolutions/laravel-onedrive-filesystem)[ RSS](/packages/kalprajsolutions-laravel-onedrive-filesystem/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

 [   ![Logo for Laravel Onedrive Filesystem](https://github.com/Pushkraj19/Pushkraj19/raw/d72ff5e2eb7299546cd8348c25fd835a39becce0/laravel-onedrive-filesystem.png)  ](https://kalprajsolutions.com/?utm_source=github&utm_medium=banner&utm_campaign=laravel-onedrive-filesystem)

 [![Latest Version on Packagist](https://camo.githubusercontent.com/f4e7f53ed79ee9ebfc82c4c911ca1a5a55e6a3734dfd9f7446a669cd559cff5f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b616c7072616a736f6c7574696f6e732f6c61726176656c2d6f6e6564726976652d66696c6573797374656d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kalprajsolutions/laravel-onedrive-filesystem) [![Total Downloads](https://camo.githubusercontent.com/fea795b7b94efa56f8e3bcac48fd512c60046d92b33f386070d801f45b5ae665/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b616c7072616a736f6c7574696f6e732f6c61726176656c2d6f6e6564726976652d66696c6573797374656d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kalprajsolutions/laravel-onedrive-filesystem) [![License](https://camo.githubusercontent.com/9fc4ed8267bb32e7818220bb968b66bd0eb754c29d26df8c1a18cb2619a2d226/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b616c7072616a736f6c7574696f6e732f6c61726176656c2d6f6e6564726976652d66696c6573797374656d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kalprajsolutions/laravel-onedrive-filesystem) [![PHP Version](https://camo.githubusercontent.com/93cd007dd6816222e78641f9866c334af90cbf346f29f50b1d160aa80c24351a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6b616c7072616a736f6c7574696f6e732f6c61726176656c2d6f6e6564726976652d66696c6573797374656d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kalprajsolutions/laravel-onedrive-filesystem)

Laravel OneDrive Filesystem
===========================

[](#laravel-onedrive-filesystem)

Use **Microsoft OneDrive for Business** as a native Laravel filesystem disk. This package provides a drop-in OneDrive filesystem driver powered by the **Microsoft Graph API** with automatic token caching — no OAuth redirects, no manual token refresh, no boilerplate.

Works with `Storage::disk('onedrive')` exactly like local or S3 storage. Upload files, download files, manage directories, generate sharing URLs — all through Laravel's standard Storage facade.

**Laravel 10, 11, and 12** supported. **PHP 8.1+** required.

---

Why This Package?
-----------------

[](#why-this-package)

There are other OneDrive adapters for Laravel, but most of them share the same problems:

- They require you to manually handle OAuth redirects and store access tokens yourself.
- They give you a Flysystem adapter you have to wire up with `Storage::build()` instead of the familiar `Storage::disk()`.
- They don't cache tokens, so every request hits Azure AD for a new token.
- They only support one account at a time.

This package fixes all of that. It registers as a real Laravel filesystem driver, caches tokens using Laravel's cache system, and supports multiple OneDrive accounts through multiple disk configurations. You install it, add your Azure AD credentials to `.env`, and start using `Storage::disk('onedrive')` — the same way you'd use any other Laravel storage disk.

### How It Compares

[](#how-it-compares)

FeatureThis Package`justus/flysystem-onedrive``sahablibya/laravel-sharepoint-filesystem``LLoadout/microsoftgraph`Native `Storage::disk('onedrive')`✅❌ (requires `Storage::build()`)✅✅Client credentials auth (no OAuth redirect)✅❌ (manual token required)✅❌Automatic token caching✅❌✅❌Multiple OneDrive accounts✅❌❌❌Laravel 10 support✅❌✅✅Laravel 12 support✅✅✅✅Scoped base path (`GRAPH_BASE_PATH`)✅❌❌❌Pure OneDrive focus (no bloat)✅✅❌ (SharePoint included)❌ (Mail, Teams, Excel included)---

Who Is This For?
----------------

[](#who-is-this-for)

- You're building a **Laravel app on a corporate Microsoft 365 tenant** and want to store files on OneDrive for Business instead of (or alongside) S3 or local storage.
- You need a filesystem disk for **Spatie Laravel Backup** that lands on OneDrive.
- You want to give users file storage backed by OneDrive without building a custom OAuth flow.
- You're running **automated jobs, cron commands, or queues** that need to read/write OneDrive files without a browser-based login.

---

Installation
------------

[](#installation)

Install via Composer:

```
composer require kalprajsolutions/laravel-onedrive-filesystem
```

Publish the configuration file:

```
php artisan vendor:publish --tag=onedrive-config
```

This creates `config/onedrive.php` in your application.

---

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

[](#configuration)

### Environment Variables

[](#environment-variables)

Add these to your `.env` file:

```
GRAPH_CLIENT_ID=your-client-id
GRAPH_TENANT_ID=your-tenant-id
GRAPH_CLIENT_SECRET=your-client-secret
GRAPH_USER_ID=user@yourdomain.com
GRAPH_BASE_PATH=
```

### Filesystem Disk

[](#filesystem-disk)

Add the OneDrive disk to `config/filesystems.php`:

```
'disks' => [
    // ...

    'onedrive' => [
        'driver'       => 'onedrive',
        'client_id'    => env('GRAPH_CLIENT_ID'),
        'tenant_id'    => env('GRAPH_TENANT_ID'),
        'client_secret'=> env('GRAPH_CLIENT_SECRET'),
        'user_id'      => env('GRAPH_USER_ID'),
        'base_path'    => env('GRAPH_BASE_PATH'),
    ],
],
```

### Multiple Accounts

[](#multiple-accounts)

You can configure multiple OneDrive disks for different accounts:

```
'disks' => [
    'onedrive' => [
        'driver'       => 'onedrive',
        'client_id'    => env('GRAPH_CLIENT_ID'),
        'tenant_id'    => env('GRAPH_TENANT_ID'),
        'client_secret'=> env('GRAPH_CLIENT_SECRET'),
        'user_id'      => env('GRAPH_USER_ID'),
        'base_path'    => env('GRAPH_BASE_PATH'),
    ],
    'onedrive_backup' => [
        'driver'       => 'onedrive',
        'client_id'    => env('BACKUP_GRAPH_CLIENT_ID'),
        'tenant_id'    => env('BACKUP_GRAPH_TENANT_ID'),
        'client_secret'=> env('BACKUP_GRAPH_CLIENT_SECRET'),
        'user_id'      => env('BACKUP_GRAPH_USER_ID'),
        'base_path'    => env('BACKUP_GRAPH_BASE_PATH'),
    ],
],
```

---

Azure AD App Registration
-------------------------

[](#azure-ad-app-registration)

You need an Azure AD app registration with **application permissions** (not delegated). This is what allows the package to authenticate without a user login flow.

### Step 1: Register the App

[](#step-1-register-the-app)

1. Go to [Azure Portal](https://portal.azure.com) → **Azure Active Directory** → **App registrations** → **New registration**
2. Name: your app name
3. Supported account types: **Accounts in this organizational directory only** (Single tenant)
4. Redirect URI: leave blank
5. Click **Register**

### Step 2: Collect Credentials

[](#step-2-collect-credentials)

After registration, copy these values:

- **Application (client) ID** → `GRAPH_CLIENT_ID`
- **Directory (tenant) ID** → `GRAPH_TENANT_ID`

### Step 3: Create a Client Secret

[](#step-3-create-a-client-secret)

1. Go to **Certificates &amp; secrets** → **New client secret**
2. Add a description, pick an expiration, click **Add**
3. Copy the **secret value** immediately (it won't be shown again) → `GRAPH_CLIENT_SECRET`

### Step 4: Add API Permissions

[](#step-4-add-api-permissions)

1. Go to **API permissions** → **Add a permission** → **Microsoft Graph** → **Application permissions**
2. Add: `Files.ReadWrite.All`
3. Click **Grant admin consent** (requires admin role)

### Step 5: Get the User ID

[](#step-5-get-the-user-id)

1. Go to [Graph Explorer](https://developer.microsoft.com/en-us/graph/graph-explorer)
2. Sign in and run the "my profile" query
3. Copy the `id` from the response → `GRAPH_USER_ID`

---

Usage
-----

[](#usage)

All standard Laravel filesystem methods work. Here are the most common operations:

### Write and Read Files

[](#write-and-read-files)

```
use Illuminate\Support\Facades\Storage;

// Write a file
Storage::disk('onedrive')->put('documents/report.txt', 'Report content');

// Read a file
$content = Storage::disk('onedrive')->get('documents/report.txt');
```

### Upload Files from Requests

[](#upload-files-from-requests)

```
// Upload with auto-generated filename
Storage::disk('onedrive')->putFile('avatars', $request->file('avatar'));

// Upload with a custom filename
Storage::disk('onedrive')->putFileAs('documents', $request->file('document'), 'custom-name.pdf');
```

### Download Files

[](#download-files)

```
// Return a download response
return Storage::disk('onedrive')->download('document.pdf', 'my-document.pdf');

// Get a sharing URL
$url = Storage::disk('onedrive')->getUrl('document.pdf');
```

### Check, Copy, Move, Delete

[](#check-copy-move-delete)

```
// Check existence
$exists = Storage::disk('onedrive')->exists('filename.txt');

// Copy
Storage::disk('onedrive')->copy('source.txt', 'destination.txt');

// Move / Rename
Storage::disk('onedrive')->move('old-name.txt', 'new-name.txt');

// Delete
Storage::disk('onedrive')->delete('filename.txt');
```

### File Metadata

[](#file-metadata)

```
$size      = Storage::disk('onedrive')->size('filename.txt');
$timestamp = Storage::disk('onedrive')->lastModified('filename.txt');
$mime      = Storage::disk('onedrive')->mimeType('filename.txt');
```

### Directory Operations

[](#directory-operations)

```
// Create a directory
Storage::disk('onedrive')->createDirectory('Documents/NewFolder');

// List files
$files = Storage::disk('onedrive')->files('Documents');

// List files recursively
$allFiles = Storage::disk('onedrive')->allFiles('Documents');

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

// Delete a directory and its contents
Storage::disk('onedrive')->deleteDirectory('Documents/OldFolder');
```

---

Available Methods
-----------------

[](#available-methods)

MethodDescription`put($path, $contents)`Write content to a file`putFile($path, $file)`Upload a file`putFileAs($path, $file, $name)`Upload with a custom name`get($path)`Read file content`download($path, $name)`Download as a response`exists($path)`Check if file exists`delete($path)`Delete a file`copy($source, $destination)`Copy a file`move($source, $destination)`Move / rename a file`size($path)`Get file size`lastModified($path)`Get last modified timestamp`mimeType($path)`Get MIME type`files($directory)`List files in a directory`directories($directory)`List directories`allFiles($directory)`List all files recursively`allDirectories($directory)`List all directories recursively`createDirectory($path)`Create a directory`deleteDirectory($directory)`Delete a directory`getUrl($path)`Get a sharing URL---

Spatie Laravel Backup
---------------------

[](#spatie-laravel-backup)

This package works as a backup destination for [spatie/laravel-backup](https://github.com/spatie/laravel-backup). Configure your backup disk:

```
// config/backup.php
'destination' => [
    'disks' => ['onedrive'],
],
```

Then run your backup as usual:

```
php artisan backup:run
```

---

Token Caching
-------------

[](#token-caching)

Access tokens are automatically cached using Laravel's default cache driver. You don't need to configure anything — the package handles token acquisition and refresh transparently. Make sure your cache driver is properly configured (Redis, Memcached, or database all work fine).

---

FAQ
---

[](#faq)

### What Laravel versions are supported?

[](#what-laravel-versions-are-supported)

Laravel 10, 11, and 12.

### Can I use this with personal Microsoft accounts?

[](#can-i-use-this-with-personal-microsoft-accounts)

This package is built for **OneDrive for Business** (Microsoft 365 / organizational accounts). Personal Microsoft accounts (`@outlook.com`, `@hotmail.com`) may require additional configuration and are not officially supported.

### How do I use a scoped base path?

[](#how-do-i-use-a-scoped-base-path)

Set `GRAPH_BASE_PATH` in your `.env` to a folder name. All file operations will be relative to that folder inside OneDrive. For example, `GRAPH_BASE_PATH=MyApp` means `Storage::disk('onedrive')->put('file.txt', ...)` writes to `MyApp/file.txt` in OneDrive.

### Does this support large file uploads?

[](#does-this-support-large-file-uploads)

Yes. The adapter uses Microsoft Graph upload sessions for files that exceed the simple upload limit.

### How do I get support?

[](#how-do-i-get-support)

Open an issue on [GitHub](https://github.com/kalprajsolutions/laravel-onedrive-filesystem/issues) or email .

---

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for recent changes.

Contributing
------------

[](#contributing)

See [CONTRIBUTING.md](CONTRIBUTING.md) for details. Contributions, bug reports, and feature requests are welcome.

Security
--------

[](#security)

If you discover a security vulnerability, email  instead of opening a public issue.

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE) for details.

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance79

Regular maintenance activity

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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

140d ago

### Community

Maintainers

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

---

Top Contributors

[![Pushkraj19](https://avatars.githubusercontent.com/u/29335514?v=4)](https://github.com/Pushkraj19 "Pushkraj19 (5 commits)")

---

Tags

backupdatabaselaravelonedriveonedrive-clientphpzip

### Embed Badge

![Health badge](/badges/kalprajsolutions-laravel-onedrive-filesystem/health.svg)

```
[![Health](https://phpackages.com/badges/kalprajsolutions-laravel-onedrive-filesystem/health.svg)](https://phpackages.com/packages/kalprajsolutions-laravel-onedrive-filesystem)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9742.3M121](/packages/roots-acorn)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[plank/laravel-mediable

A package for easily uploading and attaching media files to models with Laravel

8251.6M13](/packages/plank-laravel-mediable)[laravel/ai

The official AI SDK for Laravel.

9782.1M162](/packages/laravel-ai)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[moonshine/moonshine

Laravel administration panel

1.3k239.9k76](/packages/moonshine-moonshine)

PHPackages © 2026

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