Skip to content

Commit 9b2b8d4

Browse files
committed
Update queues.md
1 parent ab85cc2 commit 9b2b8d4

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

docs/v3/msgraph/queues.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,52 @@
22
title: Queues
33
---
44

5-
If you want to use `MsGraph` within a job or command, you can use the `login` method to authenticate the user. Make sure to pass the user model to the `login` method. The User needs to have the `access_token` and `refresh_token` stored in the database.
5+
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:
66

77
```php
8-
MsGraph::login(User:find(1));
9-
10-
MsGraph->get('me');
8+
MsGraph::login(User::find(1));
9+
MsGraph::get('me');
1110
```
1211

13-
Example Job:
12+
Here's an example of how to structure a job that uses `MsGraph`:
1413

1514
```php
1615
<?php
1716

1817
namespace App\Jobs;
1918

2019
use App\Models\User;
21-
// ...
22-
23-
class ExampleJob implements ShouldQueue
20+
use Dcblogdev\MsGraph\Facades\MsGraph;
21+
use Illuminate\Bus\Queueable;
22+
use Illuminate\Contracts\Queue\ShouldQueue;
23+
use Illuminate\Foundation\Bus\Dispatchable;
24+
use Illuminate\Queue\InteractsWithQueue;
25+
use Illuminate\Queue\SerializesModels;
26+
27+
class ExampleMsGraphJob implements ShouldQueue
2428
{
2529
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
2630

27-
public $user;
31+
protected $user;
2832

29-
/**
30-
* Create a new job instance.
31-
*/
3233
public function __construct(User $user)
3334
{
3435
$this->user = $user;
3536
}
3637

37-
/**
38-
* Execute the job.
39-
*/
4038
public function handle(): void
4139
{
4240
MsGraph::login($this->user);
43-
44-
$me = MsGraph::get("me");
41+
$userData = MsGraph::get('me');
42+
// Process $userData as needed
4543
}
4644
}
47-
```
45+
```
46+
47+
Dispatch this job with a user instance:
48+
49+
```php
50+
ExampleMsGraphJob::dispatch($user);
51+
```
52+
53+
This approach ensures that the Microsoft Graph API calls are made with the correct user context, even in background processes.

0 commit comments

Comments
 (0)