Tustin / psn-php

A PHP wrapper for the PSN API
https://tustin.dev/psn-php/
MIT License
354 stars 73 forks source link

Invalid argument supplied for foreach on avatarUrl #208

Closed vicegold closed 1 year ago

vicegold commented 2 years ago

Both avatarUrl and avatarUrls return this error Invalid argument supplied for foreach on line 160 in tustin/psn-php/src/Model/User.php when using search() on 3.0.

gabetavares commented 2 years ago

Could you provide some code?

The code seems to be working pretty fine.

Here are the code for avatars for a single user:

$username = 'psnuserhere';

$acc = $client->users()->search($username)->first()->accountId();
$user = $client->users()->find($acc);

var_dump($user->avatarUrls());

foreach ($user->avatarUrls() as $avatarUrl) {
    echo $avatarUrl;
}

Or in case you are trying to search the users and get their avatars:

$searchTerm = 'psnuserhere'
$users = $client->users()->search($searchTerm );

foreach ($users as $user) {
    var_dump($user->avatarUrls());
}
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.