Hi @altoin !
Check the documentation: https://laravel.com/docs/4.2/eloquent#one-to-many
To get the results you have to write:
Publisher::find(1)->videos;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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
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.