belongsTo(Video::class); } public function user() { return $this->belongsTo(User::class); } public function parent() { return $this->belongsTo(Comment::class, 'parent_id'); } public function replies() { return $this->hasMany(Comment::class, 'parent_id')->latest(); } // Get mentioned users from comment body public function getMentionedUsers() { preg_match_all('/@(\w+)/', $this->body, $matches); if (empty($matches[1])) { return collect(); } return User::whereIn('username', $matches[1])->get(); } // Parse mentions and make them clickable public function getParsedBodyAttribute() { $body = e($this->body); $body = preg_replace('/@(\w+)/', '@$1', $body); return $body; } }