Skip to content

Comment Model ​

DB Table Name{wp_db_prefix}fbs_comments
SchemaCheck Schema
Source Filefluent-boards/app/Models/Comment.php
Name SpaceFluentBoards\App\Models
ClassFluentBoards\App\Models\Comment

Global eager loads

The model registers two global scopes, images and replies, that always eager-load those relations. Remove them with Comment::withoutGlobalScopes(['images', 'replies']) when you do not need them.

Attributes ​

AttributeData TypeComment
idINT UNSIGNEDPrimary key
board_idINT UNSIGNEDBoard ID
task_idINT UNSIGNEDTask ID
parent_idBIGINT UNSIGNED NULLParent comment for replies. Values below 1 are saved as NULL
typeVARCHAR(50) NULLcomment (default), note or reply
privacyVARCHAR(50) NULLpublic or private. The model sets private when empty
statusVARCHAR(50) NULLpublished (default), draft or spam
author_nameVARCHAR(192) NULLFilled from the WP user on create
author_emailVARCHAR(192) NULLFilled from the WP user on create
author_ipVARCHAR(50) NULLAuthor IP
descriptionTEXT NULLComment body (HTML)
created_byBIGINT UNSIGNED NULLAuthor user ID. Defaults to the current user
settingsTEXT NULLSerialized; returned as an array
created_atTIMESTAMP NULL
updated_atTIMESTAMP NULL

Appended attributes:

AttributeComment
avatarAvatar URL for the author, from fluent_boards_user_avatar()

Model events ​

  • creating: fills created_by, type, privacy, author_email and author_name.
  • created / deleted: increments / decrements the task's comments_count for type = 'comment'.
  • deleting: deletes the comment's images and their files.

Usage ​

Please check Model Basic for common methods.

php
$comment = FluentBoards\App\Models\Comment::create([
    'board_id'    => 1,
    'task_id'     => 42,
    'description' => '<p>Looks good to me.</p>',
]);

Scopes ​

byTask($taskId) ​

php
$comments = FluentBoards\App\Models\Comment::byTask(42)->whereNull('parent_id')->get();

privacy($privacy) ​

php
$public = FluentBoards\App\Models\Comment::byTask(42)->privacy('public')->get();

type($type) ​

php
$notes = FluentBoards\App\Models\Comment::byTask(42)->type('note')->get();

Relations ​

task ​

  • Returns FluentBoards\App\Models\Task

user ​

The author (created_by).

  • Returns FluentBoards\App\Models\User

replies ​

Comments whose parent_id is this comment.

  • Returns a collection of FluentBoards\App\Models\Comment
php
$replies = $comment->replies;

images ​

Images attached to the comment (fbs_attachments, object_type = 'comment_image').

  • Returns a collection of FluentBoards\App\Models\CommentImage

parentComment ​

WARNING

Despite its name, this relation is defined as hasOne(Comment::class, 'parent_id', 'id'), so it returns the first reply to this comment, not its parent. To get the parent, use Comment::find($comment->parent_id).

  • Returns FluentBoards\App\Models\Comment or null