morphTo('entity'); } /** * Get the parent comment this is in reply to (if existing). * @return BelongsTo */ public function parent(): BelongsTo { return $this->belongsTo(Comment::class, 'parent_id', 'local_id', 'parent') ->where('commentable_type', '=', $this->commentable_type) ->where('commentable_id', '=', $this->commentable_id); } /** * Check if a comment has been updated since creation. */ public function isUpdated(): bool { return $this->updated_at->timestamp > $this->created_at->timestamp; } public function logDescriptor(): string { return "Comment #{$this->local_id} (ID: {$this->id}) for {$this->commentable_type} (ID: {$this->commentable_id})"; } public function safeHtml(): string { return HtmlContentFilter::removeScriptsFromHtmlString($this->html ?? ''); } public function jointPermissions(): HasMany { return $this->hasMany(JointPermission::class, 'entity_id', 'commentable_id') ->whereColumn('joint_permissions.entity_type', '=', 'comments.commentable_type'); } /** * Scope the query to just the comments visible to the user based upon the * user visibility of what has been commented on. */ public function scopeVisible(Builder $query): Builder { return app()->make(PermissionApplicator::class) ->restrictEntityRelationQuery($query, 'comments', 'commentable_id', 'commentable_type'); } }