Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Have you assigned the Comment -> User relationship? For instance..

class Comment {
 
    public function Author(){
        return $this->belongsTo('User');
    }

}

class User {

    public function Comments(){
        return $this->hasMany('Comment');
    }

}

Then, when pulling a single $comment object, you'd be able to do

$comment->author->username
Last updated 2 years ago.
0

thank you, now i understand how to use eloquent on my project.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.