Search code examples
phpmicrosoft-graph-api

msgraph-sdk-php v2 how to get data from returned object?


im using msgraph-sdk-php v2.2.0 library to get last access of user to microsoft office365 service

$request = new UsersRequestBuilderGetRequestConfiguration();
$request->queryParameters = UsersRequestBuilderGetRequestConfiguration::createQueryParameters();
$request->queryParameters->filter = "startswith(userPrincipalName,'".$data['user']."')";
$request->queryParameters->select = ['signInActivity'];

$user = $o365->users()->get($request)->wait();

everything works ok.

but getting data from $user object is painfull:

$user->getBackingStore()->enumerate()['value'][0]->getBackingStore()->enumerate()['signInActivity']->getBackingStore()->enumerate();

is there a simplier way to do that?

thank you.


Solution

  • You can call getValue() to access array of users and getSignInActivity() on specific user.

    $user->getValue()[0]->getSignInActivity();