I am using the the Laravel Http Client to get a collection of users from the Microsoft Graph API. My code as follows is:
public function index()
{
$response = Http::withToken($this->accessToken)
->get('https://graph.microsoft.com/v1.0/users');
foreach($response['value'] as $user)
{
echo $user['displayName'] . '<br/>';
}
}
However, I want to be able to access user details as properties such as:
public function index()
{
$response = Http::withToken($this->accessToken)
->get('https://graph.microsoft.com/v1.0/users');
foreach($response->value as $user)
{
echo $user->displayName . '<br/>';
}
}
How would I go about this?
UPDATE
public function index()
{
$response = Http::withToken($this->accessToken)
->get('https://graph.microsoft.com/v1.0/users')
->throw();
$users = $response->object();
foreach($users->value as $user)
{
echo $user->displayName . '<br/>';
}
}
$response->object(). Ref: laravel.com/docs/8.x/http-client#making-requests