October CMS: User extended module throw an error

84 Views Asked by At

I have installed OCtoberCMS, and use User Extended plugin to make a profile page.

component

When i try to use component to show Friends reques, the page throws me an error

Call to a member function take() on array

the error

Here is the function:

public static function listReceivedFriendRequests($limit = 5)
{
    $users = new Collection();
    
    $limit = Helpers::unlimited($limit);
    
    $requests = Friend::friendRequests()->take($limit);
    
    foreach ($requests as $user) {
        $users->push(UserUtil::getRainlabUser($user->user_that_sent_request));
    }
    return $users;
}

This happened when user never has an friend request. Onece if they have a friend request this error not show anymore. How can I fix it?

1

There are 1 best solutions below

0
On

I just tested and make couple of changes. For now is work good, but don`t know is this the best way to do this :D

     public static function listReceivedFriendRequests($limit = 5)
    {
        $users = new Collection();

        $limit = Helpers::unlimited($limit);

$requests = Friend::friendRequests();
        if(!empty($requests))
        {
            $requests = Friend::friendRequests()->take($limit);
        }
         

        foreach ($requests as $user) {
            $users->push(UserUtil::getRainlabUser($user->user_that_sent_request));
        }
        return $users;
    }