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
  • MsGraph
    • Is Connected
    • Disconnect
    • Middleware
    • Queues
    • Login with MsGraph
    • Contacts
    • Emails
    • Files
    • Filesystem
  • MsGraph Admin
    • Middleware
    • Contacts
    • Emails
Navigation
  • Introduction
  • Install
  • MsGraph
    • Is Connected
    • Disconnect
    • Middleware
    • Queues
    • Login with MsGraph
    • Contacts
    • Emails
    • Files
    • Filesystem
  • MsGraph Admin
    • Middleware
    • Contacts
    • Emails

Queues

When using MsGraph within jobs, commands, or other queued processes, you need to authenticate the user explicitly. Ensure the user model has access_token and refresh_token stored in the database. Use the login method to authenticate the user before making any API calls:

MsGraph::login(User::find(1));
MsGraph::get('me');

Here's an example of how to structure a job that uses MsGraph:

<?php

namespace App\Jobs;

use App\Models\User;
use Dcblogdev\MsGraph\Facades\MsGraph;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ExampleMsGraphJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $user;

    public function __construct(User $user)
    {
        $this->user = $user;
    }

    public function handle(): void
    {
        MsGraph::login($this->user);
        $userData = MsGraph::get('me');
        // Process $userData as needed
    }
}

Dispatch this job with a user instance:

ExampleMsGraphJob::dispatch($user);

This approach ensures that the Microsoft Graph API calls are made with the correct user context, even in background processes.

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