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

MsGraph Admin

Only administrators can login as tenants.

A routes example:

Route::group(['middleware' => ['web', 'auth']], function(){
    Route::get('msgraph', function(){

        if (! MsGraphAdmin::isConnected()) {
            return MsGraphAdmin::connect();
        } else {
            //display all users
            return MsGraphAdmin::get('users');
        }

    });

    Route::get('msgraph/connect', function(){
        return MsGraphAdmin::connect();
    });
});

Or using a middleware route, if user does not have a graph token then automatically redirect to get authenticated:

Route::group(['middleware' => ['web', 'MsGraphAdminAuthenticated']], function(){
    Route::get('msgraph', function(){
        //fetch all users
        return MsGraphAdmin::get('users');
    });
});

Route::get('msgraph/connect', function(){
    return MsGraphAdmin::connect();
});

Once authenticated you can call MsGraph:: with the following verbs:

MsGraphAdmin::get($endpoint, $array = [])
MsGraphAdmin::post($endpoint, $array = [])
MsGraphAdmin::put($endpoint, $array = [])
MsGraphAdmin::patch($endpoint, $array = [])
MsGraphAdmin::delete($endpoint, $array = [])

The second param is array is not always required, its requirement is determined from the endpoint being called, see the API documentation for more details.

These expect the API endpoints to be passed, the url https://graph.microsoft.com/beta/ is provided, only endpoints after this should be used ie:

MsGraphAdmin::get('users');

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