PHPackages                             lloadout/microsoftgraph - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. lloadout/microsoftgraph

ActiveLibrary[File &amp; Storage](/categories/file-storage)

lloadout/microsoftgraph
=======================

Laravel package for Microsoft graph (Microsoft 365). Manage mail, OneDrive, Teams, Excel, Calendars and Contacts with ease

v1.20(5mo ago)285.6k↑57.7%10[1 issues](https://github.com/LLoadout/microsoftgraph/issues)MITPHPPHP ^8.1CI passing

Since Mar 9Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/LLoadout/microsoftgraph)[ Packagist](https://packagist.org/packages/lloadout/microsoftgraph)[ Docs](https://github.com/lloadout/microsoftgraph)[ RSS](/packages/lloadout-microsoftgraph/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (7)Versions (27)Used By (0)

 [![](https://github.com/LLoadout/assets/raw/master/LLoadout_microsoftgraph.png "LLoadout logo")](https://github.com/LLoadout/assets/blob/master/LLoadout_microsoftgraph.png)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f16fbac63f82f3e76225daf27e34a9df185828f3860854a6c3880063d9285f34/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6c6f61646f75742f6d6963726f736f667467726170682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lloadout/microsoftgraph)[![Total Downloads](https://camo.githubusercontent.com/b613e41100030f8586a158ee630ac63fe97b03c55a4e9c0823bf3196a43c6691/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6c6f61646f75742f6d6963726f736f667467726170682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lloadout/microsoftgraph)

Laravel Microsoft graph
=======================

[](#laravel-microsoft-graph)

Use case
--------

[](#use-case)

Laravel package for using Microsoft mail, OneDrive, Teams, Excel, Calendars and Contacts

This package makes a wrapper around the Microsoft Graph API.

1. It provides a [Mail](#mail-usage) driver for Microsoft mail.
2. It provides a storage driver for [OneDrive](#storage-usage).
3. It provides functionality to interact with Microsoft [Teams](#teams-usage).
4. It provides the possibility to work with [Excel](#excel-usage), making it possible to write and read Excel files.
5. It allows you to manage [calendar](#calendar-usage) events.
6. It allows you to manage [contacts](#contacts-usage).
7. It allows you to read and handle [mail](#reading-and-handling-mail).

You need to register an app in the Microsoft Azure Portal to use this package. Follow the steps in the Microsoft docs:

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

[](#installation)

You can install the package via composer:

```
composer require lloadout/microsoftgraph
```

Add this to your .env file and fill it with the values you specified in Microsoft Azure Portal app registration.
If you created a multi-tenant app in Azure AD than you don't put your tentant id into the `MS_TENANT_ID` variable but you set it to `common`.

```
MS_TENANT_ID=
MS_CLIENT_ID=
MS_CLIENT_SECRET=
MS_GRAPH_API_VERSION=v1.0
MS_REDIRECT_URL=https://your-url.com/microsoft/callback
MS_REDIRECT_AFTER_CALLBACK_URL=https://your-url.com/dashboard

```

Connect your account
--------------------

[](#connect-your-account)

The package uses OAuth and provides two routes

The first redirects you to the consent screen of Microsoft

```
https://your-url.com/microsoft/connect

```

The second is the callback url you need to specify in Microsoft Azure Portal app registration as redirect uri

```
https://your-url.com/microsoft/callback

```

The callback will fire an MicrosoftGraphCallbackReceived event, you have to listen for this event in your EventServiceProvider and store the accessData to a session variable `microsoftgraph-access-data`. You can add your token store logic in a listener for this event.

```
public function boot()
{
    Event::listen(function (MicrosoftGraphCallbackReceived $event) {
        session()->put('microsoftgraph-access-data', $event->accessData);
    });
}

```

The package will search for a session variable name `microsoftgraph-access-data` for establishing the connection. So please provide this variable with your accessData as value when logging in. For example: On login, you get your accesData from the database and store it into the session variable `microsoftgraph-access-data`.

After the callback, the package will redirect you to the url you specified in the `MS_REDIRECT_AFTER_CALLBACK_URL` variable. If this variable is not set, the package will redirect to the root of your application.

Mail usage
----------

[](#mail-usage)

### Configuration

[](#configuration)

You have to provide this API permissions: `Mail.send`

Set the environment variable MAIL\_MAILER in your .env file

```
MAIL_MAILER=microsoftgraph

```

note: make sure your from address is the address you gave the consent to

### Usage

[](#usage)

```
Mail::send(new YourMailable());

Mail::raw('The body of my first test message', function($message) {
    $message->to('john@doe.com', 'John Doe')->subject('A mail send via lloadout/microsoftgraph');
});
```

### Reading and handling mail

[](#reading-and-handling-mail)

You have to provide this API permissions: `Mail.Read, Mail.ReadWrite, Mail.ReadBasic`

#### Available methods

[](#available-methods)

```
    getMailFolders(): array|GraphResponse|mixed
    getSubFolders(id): array|GraphResponse|mixed
    getMailMessagesFromFolder([folder: string = 'inbox'], [isRead: true = true], [skip: int = 0], [limit: int = 20]): array
    updateMessage(id, data): array|GraphResponse|mixed
    moveMessage(id, destinationId): array|GraphResponse|mixed
    getMessage(id): array|GraphResponse|mixed
    getMessageAttachements(id): array|GraphResponse|mixed
```

```
    $mail = app(Mail::class);

    collect($mail->getMailFolders())->each(function($folder){
        echo $folder['displayName']."";
    });

    //get all unread messages from inbox
    collect($mail->getMailMessagesFromFolder('inbox', isRead: false))->each(function($message) use ($mail){
        echo $message['subject']."";
    });

```

Storage usage
-------------

[](#storage-usage)

### Configuration

[](#configuration-1)

You have to provide this API permissions: `Files.ReadWrite.all`

add the onedrive root to your .env file:

```
MS_ONEDRIVE_ROOT="me/drive/root"

```

### Available methods

[](#available-methods-1)

All methods from the Laravel Storage facade are available.

### Usage

[](#usage-1)

The package created a disk called `onedrive`. This means that you can use all the methods as described in the Laravel docs:

```
$disk = Storage::disk('onedrive');
#create a dir
$disk->makeDirectory('Test folder');
#storing files
$disk->put('Test folder/file1.txt','Content of file 1');
$disk->put('Test folder/file2.txt','Content of file 2');
#getting files
Storage::disk('onedrive')->get('Test folder/file1.txt');
```

Teams usage
-----------

[](#teams-usage)

### Configuration

[](#configuration-2)

You have to provide this API permissions: `Chat.ReadWrite`

### Available methods

[](#available-methods-2)

```
    getJoinedTeams(): array|GraphResponse|mixed
    getChannels(team): array|GraphResponse|mixed
    getChats(): array|GraphResponse|mixed
    getChat(id): array|GraphResponse|mixed
    getMembersInChat(chat): array|GraphResponse|mixed
    send(teamOrChat, message): array|GraphResponse|mixed
```

### Usage

[](#usage-2)

First instantiate the Teams class

```
$teamsClass = new Teams();
```

Get all the teams you are a member of ( additional permissions needed: `Group.Read.All` )

```
$joinedTeams = $teamsClass->getJoinedTeams();
```

Get alle the channels for a team ( additional permissions needed: `Group.Read.All` )

```
$channels = $teamsClass->getChannels($team);
```

Get all the chats for a user ( additional permissions needed: `Chat.Read.All` )

```
$chats = $teamsClass->getChats();
```

Get a chat by a given id ( additional permissions needed: `Chat.Read.All` )

```
$chats = $teamsClass->getChat('your-chat-id');
```

Get all the members in a channel ( additional permissions needed: `ChannelMessage.Read.All` )

```
$members = $teamsClass->getMembersInChat($chat));
```

Send a message to a channel ( additional permissions needed: `ChannelMessage.Send` )

```
$teamsClass->send($teamOrChat,'Hello world!');
```

Excel usage
-----------

[](#excel-usage)

### Configuration

[](#configuration-3)

You have to provide this API permissions: `Files.ReadWrite.all`

### Available methods

[](#available-methods-3)

```
    loadFile(file): void
    loadFileById(fileId): void
    setCellValues(cellRange, values: array): void
    getCellValues(cellRange): array
    recalculate(): void
    createSession(fileId): string
```

### Usage

[](#usage-3)

First instantiate the Excel class

```
$excelClass = new Excel();
```

Load a file from OneDrive

```
$excelClass->loadFile('Test folder/file1.xlsx');
```

Load a file by its id

```
$excelClass->loadFileById($fileId);
```

Set cell values of a range

```
$values = ['B1' => null, 'B2' => '01.01.23', 'B3' => 3, 'B4' => '250', 'B5' => '120', 'B6' => '30 cm', 'B7' => null, 'B8' => null, 'B9' => null, 'B10' => null, 'B11' => null, 'B12' => 2];
$excelClass->setCellValues('B1:B12', $values);
$excelClass->getCellValues('H1:H20');
```

Calendar usage
--------------

[](#calendar-usage)

### Configuration

[](#configuration-4)

You have to provide this API permissions: `Calendars.ReadWrite`

### Available methods

[](#available-methods-4)

```
    getCalendars(): array
    getCalendarEvents(calendar: Calendar): array
    saveEventToCalendar(calendar: Calendar, event: Event): GraphResponse|mixed
    makeEvent(starttime: string, endtime: string, timezone: string, subject: string, body: string, [attendees: array = [...]], [isOnlineMeeting: bool = false]): Event
```

### Usage

[](#usage-4)

First instantiate the Calendar class

```
$calendarClass = new Calendar();
```

Get all the calendars

```
$calendars = $calendarClass->getCalendars();
```

Get all the events for a calendar

```
$events = $calendarClass->getCalendarEvents($calendar);
```

Save an event to a calendar, the event object is a MicrosoftGraphEvent object We made a helper function to create an event object `Calendar::makeEvent(string $starttime, string $endtime, string $timezone, string $subject, string $body, array $attendees = [], bool $isOnlineMeeting = false)`

```
$calendarClass->saveEvent($calendar, $event);
```

Contacts usage
--------------

[](#contacts-usage)

### Configuration

[](#configuration-5)

You have to provide this API permissions: `Contacts.ReadWrite`

### Available methods

[](#available-methods-5)

```
    getContacts(): array
```

### Usage

[](#usage-5)

First instantiate the Contacts class

```
$contactsClass = new Contacts();
```

Get all the contacts

```
$contacts = $contactsClass->getContacts();
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Dieter Coopman](https://github.com/LLoadout)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance70

Regular maintenance activity

Popularity36

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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

Every ~41 days

Recently: every ~81 days

Total

26

Last Release

172d ago

Major Versions

v0.5 → v1.02023-03-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/0a5498402f8114208ae9befe10cb82ea43e33e256ce22c96ff0ec97cb6c87fc5?d=identicon)[dietercoopman](/maintainers/dietercoopman)

---

Top Contributors

[![dietercoopman](https://avatars.githubusercontent.com/u/4672752?v=4)](https://github.com/dietercoopman "dietercoopman (103 commits)")

---

Tags

contactseventsexcelfilesystemgraphapilaravelmaildrivermicrosoftteamslaravelmicrosoftgraphLLoadout

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/lloadout-microsoftgraph/health.svg)

```
[![Health](https://phpackages.com/badges/lloadout-microsoftgraph/health.svg)](https://phpackages.com/packages/lloadout-microsoftgraph)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M100](/packages/dedoc-scramble)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.3k3](/packages/defstudio-telegraph)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

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