Laravel Developer
David Carr
Web Developer
All Posts Archives Categories Authors
About Books Packages Templates Contact
Blog
All Posts Archives Categories Authors
About Books Packages Templates Contact
Laravel Microsoft Graph
Laravel Packages
Laravel Microsoft Graph Laravel Xero Laravel Sent Emails Laravel Dropbox Laravel Box Laravel Companies House Laravel Countries Laravel Eventbrite Laravel Blade Components
PHP Packages
PDO Wrapper PHP find and replace JSON SQL Import IMAP Export CSV Pagination
v3 v4
Navigation
  • Introduction
  • Install
  • Delta
  • MsGraph
    • Is Connected
    • Disconnect
    • Middleware
    • Queues
    • Login with MsGraph
    • Contacts
    • Emails
    • Files
    • Filesystem
  • MsGraph Admin
    • Middleware
    • Contacts
    • Emails
Navigation
  • Introduction
  • Install
  • Delta
  • MsGraph
    • Is Connected
    • Disconnect
    • Middleware
    • Queues
    • Login with MsGraph
    • Contacts
    • Emails
    • Files
    • Filesystem
  • MsGraph Admin
    • Middleware
    • Contacts
    • Emails

Add Sharepoint/OneDrive file storage

Add Sharepoint/OneDrive file storage

This package make use of shitware-ltd/flysystem-msgraph internally

A flysystem 3.0 adapter for Sharepoint 365 / OneDrive using Microsoft Graph API with support for uploading large files

Since flysystem-msgraph package uses the official Microsoft Graph SDK you can use Microsoft Graph directly by calling

$graph = new \Microsoft\Graph\Graph;

Set up

In filesystems.php add

'msgraph' => [
    'driver' => 'msgraph',
    'driveId' => env('MSGRAPH_DRIVEID', ''),
],

Inside .env add a key:

Add the drive id to be used.

MSGRAPH_DRIVEID=''

To find your drives use the Graph Explorer https://developer.microsoft.com/en-us/graph/graph-explorer

Login and then enter the url https://graph.microsoft.com/v1.0/drives

Inside the returned payload you’re looking for an id property that looks like this:

"id": "b!zMM792FbNkq...",

Usage

using the msgraph driver is a case of specifying the disk Storage::disk('msgraph')

A few examples:

//make folder
Storage::disk('msgraph')->makeDirectory('assets');

//upload file
Storage::disk('msgraph')->put('demo.txt', 'hello');

//move demo.txt from a test folder to the root
Storage::disk('msgraph')->move('test/demo.txt', 'demo.txt');

//copy demo.txt from the root to a test folder
Storage::disk('msgraph')->copy('demo.txt', 'test/demo.txt');

//download file
Storage::disk('msgraph')->download('demo2.txt');

//get a list of files from the root
Storage::disk('msgraph')->files();

//get a list of folders from the root
Storage::disk('msgraph')->directories();

See https://laravel.com/docs/10.x/filesystem for more details on using Laravel file storage.

Table of Contents
  • Add Sharepoint/OneDrive file storage
    • Set up
    • Usage

DCBlog

Practical tutorials, code snippets, and in-depth guides for modern web development. Helping developers build better applications since 2009.

Subscribe to my newsletter for the latest updates on my books and digital products.

© 2009 - 2025 DC Blog. All rights reserved.

Privacy Policy • Terms of Service