$list = Comment::where('article_id', 1)->get()->load('user');
$users = $list->map(function($list){
return $list->user;
})->unique();
Comment (article_id, id, text, user_id)
Article (id, text, user_id)
User (id, name)
public function comments(){
return $this->hasMany(Comment::class);
}
public function author(){
return $this->belongsTo(User::class);
}
public function commetators(){
return $this->hasManyThrough(User::class, Comment::class);
public function article(){
return $this->belongsTo(Article::class);
}
public function user(){
return $this->belongsTo(User::class);
}
$users = Article::find(1)->commentators;