beyondcode/laravel-comments

Commentor Name

Closed this issue · 3 comments

Hi, How can I add commentor name? for non logged in user?

I have the same request .. I could bring the user_id but it will be great of you can get the name of even eager load the user object along with each comment when run for example $post->comments

Hey @alzaabi98

You can get the user object by calling the relationship of ->commentator on the comment object.

You can also load in the commenter on all comments using

$comments = $post->comments;
$comments->load('commentator');

@frankperez87 You can do that by eager loading the commentator instead, it will save you one query.

$posts->comments()->with('commentator')->get();