Download the PHP package prasadchinwal/microsoft-graph without Composer
On this page you can find all versions of the php package prasadchinwal/microsoft-graph. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download prasadchinwal/microsoft-graph
More information about prasadchinwal/microsoft-graph
Files in prasadchinwal/microsoft-graph
Package microsoft-graph
Short Description Package for working with Microsoft Graph API
License MIT
Informations about the package microsoft-graph
Laravel Microsoft Graph
A comprehensive Laravel wrapper for Microsoft Graph API that provides an elegant, fluent interface for interacting with Microsoft 365 services including users, calendars, events, mail, and more.
Features
- 🚀 Easy Integration - Simple, Laravel-style fluent API
- ⚡ Performance - Automatic OAuth token caching with expiry handling
- 🔒 Type Safe - Full support for PHP 8.2+ with strict types and return type declarations
- 🎯 Data Objects - Strongly-typed responses using Spatie Laravel Data
- 🛡️ Error Handling - Custom exceptions with clear, actionable error messages
- 📧 Email & Calendar - Full support for Outlook, calendars, events, and mail
- 👥 User Management - Complete user CRUD operations with license management
- 🖼️ Profile Photos - Upload, download, and delete user profile photos
- 📎 Attachment Management - Upload, download, and manage file, item, and reference attachments
- 📝 Query Filters - OData query filtering for events and calendars
- 🔧 Laravel 10-12 - Supports Laravel 10.x, 11.x, and 12.x
Requirements
- PHP 8.2 or higher
- Laravel 10.0, 11.0, or 12.0
- Microsoft Azure App Registration with appropriate permissions
Installation
Install the package via Composer:
Publish the configuration file:
This will create a config/microsoft-graph.php file in your application.
Configuration
1. Azure App Registration
Before using this package, you need to register an application in the Azure Portal:
- Navigate to Azure Active Directory > App registrations
- Click New registration
- Give your app a name and select supported account types
- Click Register
- Note down the Application (client) ID and Directory (tenant) ID
- Go to Certificates & secrets > New client secret
- Create a new secret and note down its value
- Go to API permissions and add the required Microsoft Graph permissions:
User.Read.AllUser.ReadWrite.AllCalendars.ReadCalendars.ReadWriteMail.ReadMail.Send- Grant admin consent for your organization
2. Environment Configuration
Add the following to your .env file:
3. Configuration File
The config/microsoft-graph.php file contains:
Note: The package will validate configuration on boot and throw a ConfigurationException if required values are missing.
Usage
Initialization
The package can be used via the Facade or by instantiating the class:
User Management
Get All Users
Retrieve all users in your organization.
API Reference: List Users
Get a Specific User
Retrieve a user by their email address (User Principal Name).
API Reference: Get User
Update a User
Update user properties using the User builder.
API Reference: Update User
Get User Licenses
Retrieve license details for a user.
API Reference: List License Details
Assign License to User
Assign one or more licenses to a user.
API Reference: Assign License
Profile Photos
Get User Profile Photo
Download a user's profile photo.
API Reference: Get Photo
Update User Profile Photo
Upload a new profile photo for a user.
API Reference: Update Photo
Delete User Profile Photo
Remove a user's profile photo.
API Reference: Delete Photo
Calendar Management
Get User Calendars
Retrieve all calendars for a user.
API Reference: List Calendars
Get User Schedule
Get free/busy schedule information for one or more users.
API Reference: Get Schedule
Get Calendar View
Get calendar events within a specific time range.
API Reference: List Calendar View
Event Management
Get User Events
Retrieve calendar events for a user.
API Reference: List Events
Filter Events
Use OData filters to query specific events.
API Reference: Filter Query Parameter
Create an Event
Create a new calendar event using a CalendarEvent class.
API Reference: Create Event
Step 1: Generate an event class:
Step 2: Configure the event class:
Step 3: Create the event:
Update an Event
Update an existing calendar event.
API Reference: Update Event
Accept an Event
Accept a meeting invitation.
API Reference: Accept Event
Decline an Event
Decline a meeting invitation.
API Reference: Decline Event
Cancel an Event
Cancel a meeting (organizer only).
API Reference: Cancel Event
Mail Management
Get User Messages
Retrieve email messages for a user.
API Reference: List Messages
Filter Messages
Apply OData filters to retrieve specific messages.
Sending Email
Send Email via Outlook
Send an email on behalf of a user.
API Reference: Send Mail
Team Configuration
Get User Team Configuration
API Reference: User Team Configuration
Helper Methods
Check is users Enterprise Voice is enabled:
Number Assignments
List numberAssignments
API Reference: List numberAssignments
Attachment Management
Microsoft Graph API supports three types of attachments:
- File Attachments - Binary files (up to 3MB)
- Item Attachments - Embedded contacts, events, or messages
- Reference Attachments - Links to files on OneDrive, Dropbox, etc.
List Attachments
Get all attachments for a message or event.
API Reference: List Attachments
Get Attachment Metadata
Retrieve metadata for a specific attachment.
API Reference: Get Attachment
Download Attachment Content
Download the raw binary content of a file attachment.
Add File Attachment
Upload a file attachment (up to 3MB).
API Reference: Add Attachment
From File Path:
From Binary Data:
Inline Attachment (for emails):
Add Reference Attachment
Add a link to a file stored on OneDrive, Dropbox, or other cloud storage.
Available Providers:
oneDriveBusinessoneDriveConsumerdropbox
Available Permissions:
view- Read-only accessedit- Read and write accessanonymousView- Public read-onlyanonymousEdit- Public read and writeorganizationView- Organization read-onlyorganizationEdit- Organization read and write
Add Custom Attachment
Add an attachment using custom array data for advanced scenarios.
Delete Attachment
Remove an attachment from a message or event.
API Reference: Delete Attachment
Complete Example: Sending Email with Attachments
Size Limitations
Important: The direct attachment API supports files up to 3MB. For larger files (3-150MB), use the upload session method:
Attachment Types Reference
| Type | Use Case | Max Size | Properties |
|---|---|---|---|
| fileAttachment | Documents, images, files | 3 MB | contentBytes, contentType, name |
| itemAttachment | Embedded contacts, events, messages | 3 MB | item (nested object) |
| referenceAttachment | OneDrive, SharePoint, Dropbox links | N/A | sourceUrl, providerType, permission |
Error Handling
The package includes custom exceptions for better error handling:
Exception Classes
MicrosoftGraphException- Base exception classAuthenticationException- OAuth/token errorsInvalidEmailException- Invalid email formatConfigurationException- Missing or invalid configuration
Example Usage
Configuration Validation
The package automatically validates configuration on boot:
Advanced Features
Token Caching
Access tokens are automatically cached with a 5-minute buffer before expiry. This significantly improves performance by preventing redundant OAuth requests.
To manually clear the token cache (useful for testing):
Custom Timezone
Set a custom timezone for calendar operations in your .env:
Or directly in the config file:
Data Transfer Objects
All responses are returned as strongly-typed Spatie Data objects:
Testing
The package includes factories and helpers for testing. You can mock the Microsoft Graph API in your tests:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Security
If you discover any security-related issues, please email the package author instead of using the issue tracker.
Credits
- Prasad Chinwal
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Support
For support, please open an issue on GitHub or contact the maintainer.
Links
- Microsoft Graph API Documentation: https://learn.microsoft.com/en-us/graph/
- Azure Portal: https://portal.azure.com
- Package Repository: https://github.com/prasadchinwal/microsoft-graph
All versions of microsoft-graph with dependencies
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
spatie/laravel-data Version ^4.11