A wrapper to integrate Microsoft Graph Api's to a Laravel Application.
composer require prasadchinwal/microsoft-graph
- Run
php artisan vendor:publish
and publish the config file. - Edit the
config/microsoft-graph.php
file to configure your settings. You need Tenant, Client ID and Client Secret.
-
Get users: Documentation
Retrieves all the users.
$graph = MicrosoftGraph::users()->get(); dd($graph);
-
Get user from ID: Documentation
Retrieves a user from principalName.
$graph = MicrosoftGraph::users() ->find('[email protected]'); dd($graph);
-
Get user Calendars: Documentation
Retrieves the users Calendar.
$graph = MicrosoftGraph::calendar() ->for('user_email') ->get(); dd($graph->first()->name); // To retrieve the name of the Calendar
-
Get user Schedule : Documentation
Retrieves the users Schedule.
$users = ['[email protected]', '[email protected]']; $graph = MicrosoftGraph::calendar() ->for('[email protected]') ->schedule(users:$users, from: Carbon::now(), to: Carbon::now()->addDays(2), timezone: 'UTC', interval: 60); dd($graph);
-
Get Calendar view for a user : Documentation
Retrieves the calendar view for the user.
MicrosoftGraph::calendar() ->for('[email protected]') ->view( start: \Carbon\Carbon::now()->toIso8601String(), end: \Carbon\Carbon::now()->toIso8601String(), );
-
Get user Calendar events : Documentation
Retrieves the users Calendar Events.
$graph = MicrosoftGraph::event() ->for('[email protected]') ->get(); dd($graph->first()->subject); // To retrieve subject of first event.
You can also filter the events:
For List of all filters please refer to docs https://learn.microsoft.com/en-us/graph/filter-query-parameter?tabs=http.
$graph = MicrosoftGraph::event() ->for('[email protected]') ->where("start/dateTime", "ge", "2024-04-17") ->where("end/dateTime", "le", "2024-04-26") ->get();
-
Create new Event for a user : Documentation
Creates an event in calendar for the user.
- Generate Event class using
php artisan make:graph-event TestGraphEvent
- Edit the Event class as required filling in necessary details about the event.
$graph = MicrosoftGraph::event()
->create(new TestGraphEvent());
dd($graph);
- Update an existing Event for a user : Documentation
Updates an event in calendar for the user.
- Edit the Event class as required filling in necessary details about the event.
$graph = MicrosoftGraph::event() ->update( new TestGraphEvent(), eventId:'AAMk' ); dd($graph);
-
Cancel an event for a user : Documentation
Cancels the event in calendar for the user.
$graph = MicrosoftGraph::event() ->for('[email protected]') ->cancel(eventId: 'AAMk', message:"Cancelling via web request!"); dd($graph);
-
Accept an event for a user : Documentation
Accept the event in calendar for the user.
$graph = MicrosoftGraph::event() ->for('[email protected]') ->accept(eventId: 'AAMk', message:"Accepting via web request!"); dd($graph);
-
Decline an event for a user : Documentation
Decline the event in calendar for the user.
- Edit the Event class as required filling in necessary details about the event.
$graph = MicrosoftGraph::event() ->for('[email protected]') ->decline(eventId: 'AAMk', message:"Declining via web request!"); dd($graph);