Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

altoin's avatar

Call to a member function on array()

Hello, please am having a problem with my laravel App. I have 2 models 1 for publishers and 1 for videos. But whenever i try to retrieve videos of a Publisher i get Call to a member function on array(). Please see my codes below. My Video Model

 public function Publisher()
    {
        return $this->belongsTo('App\Publisher');
    }

The Publisher Model

public function videos()
    {
        return $this->hasMany('App\Videos');
    }

But if i run

$publisher->videos();

I get Error

Call to a member function on array()

Please can someone help with this problem. Thank you

0 likes
2 replies
zachleigh's avatar
Level 47

First, be sure that $publisher is a single Publisher object. Your error makes me think its not. Then, try this:

$publisher->videos;

videos() returns the relationship and `videos' returns a collection of videos.

Please or to participate in this conversation.