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

huzzahbeard's avatar

Relationship not returning a collection

I am starting to really dip my feet into laravel and have some incorrect behavior and I am unsure how to trouble shoot it.

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Podcast;
use App\Models\Tag;


class Episode extends Model
{
    use HasFactory;

    public function podcast(){
      return $this->belongsTo(Podcast::class);
    }

    public function tags(){
      return $this->hasMany(Tag::class);
    }



}

When I run in Tinker

and get an episode collection and then run the podcast method I get this

>>> $ep->podcast();
=> Illuminate\Database\Eloquent\Relations\BelongsTo {#4001}
>>>

I thought I would get the podcast collection. There is no error just an out put of the relationship. I assume I am doing something wrong but not wrong enough to create an error. Any help is appreciated.

0 likes
2 replies
Nakov's avatar
Nakov
Best Answer
Level 73

@huzzahbeard you will not get a collection when there is a belongsTo relationship, because that means that you have one instance of a podcast.

Try this:

$ep->podcast;

without the () and you will get an instance of Podcast model.

As for the tags, getting it without the () it will return a collection of Tag class.

huzzahbeard's avatar

Bingo! Wow! So why is that called as a property and not a method? I suppose this is just something I will need to get used to.

Please or to participate in this conversation.