Currently seeking new career opportunities in web development, particularly with Laravel, Hire Me
Laravel Microsoft Graph

File System

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('log.txt', 'hello');

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

//copy log.txt from the root to an assets folder
Storage::disk('msgraph')->copy('log.txt', 'assets/log.txt');

//download file
Storage::disk('msgraph')->download('log.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.

Laravel Modules Your Logo Your Logo Your Logo

Become a sponsor

Help support the blog so that I can continue creating new content!

Sponsor

My Latest Book

Modular Laravel Book - Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Learn Laravel with Laracasts

Faster Laravel Hosting

© 2006 - 2024 DC Blog. All code MIT license. All rights reserved.