Rainieren
1 year ago

Laravel - Post owner not displaying

Posted 1 year ago by Rainieren

Hello, I'm following Jeffrey's tutorial on how to display threads and their replies, But then he displays the owner of the reply using {{ $reply->owner->name }} but when I do the same, Nothing shows on my page. It doesn't give me an error either. The same happens when I try to display the owner of the post, using {{ $post->owner->name }}

My Post model looks like this:


public function user() {
        return $this->belongsTo(User::class);
    }

    public function replies() {
        return $this->hasMany(Reply::class);
    }

    public function owner() {
        return $this->belongsTo(User::class, 'user_id');
    }

And my Reply model looks like this:

public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function post()
    {
        return $this->belongsTo(Post::class);
    }

    public function owner() {
        return $this->belongsTo(User::class, 'user_id');
    }

I don't think there is anything wrong with my relations

What is causing this problem? Thanks in advance!

Please sign in or create an account to participate in this conversation.