Skip to content

Notification Model ​

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

An in-app notification. Recipients and read state are stored in fbs_notification_users (NotificationUser).

On create, the model sets activity_by to the current user when empty, and sets created_at / updated_at with current_time('mysql').

Attributes ​

AttributeData TypeComment
idINT UNSIGNEDPrimary key
object_idINT UNSIGNEDBoard ID
object_typeVARCHAR(100)board_notification
task_idINT UNSIGNED NULLRelated task
actionVARCHAR(255) NULLFor example task_created, task_comment_mentioned
activity_byBIGINT UNSIGNEDUser who triggered it
descriptionLONGTEXT NULLNotification text
settingsTEXT NULLSerialized; returned as an array
created_atTIMESTAMP NULL
updated_atTIMESTAMP NULL

Usage ​

Please check Model Basic for common methods.

php
// Latest notifications for the current user
$notifications = FluentBoards\App\Models\Notification::whereHas('users', function ($query) {
        $query->where('user_id', get_current_user_id());
    })
    ->orderBy('id', 'DESC')
    ->limit(20)
    ->get();

Relations ​

activitist ​

The user who triggered the notification (activity_by).

  • Returns FluentBoards\App\Models\User

board ​

  • Returns FluentBoards\App\Models\Board

task ​

The related task, with stage and board eager-loaded.

  • Returns FluentBoards\App\Models\Task

users ​

Recipients (fbs_notification_users). Pivot: marked_read_at.

  • Returns a collection of FluentBoards\App\Models\User
php
foreach ($notification->users as $user) {
    $isRead = (bool) $user->pivot->marked_read_at;
}

Methods ​

checkReadOrNot() ​

Returns true when the current user has marked the notification as read.

WARNING

The method assumes the current user is a recipient. If there is no matching fbs_notification_users row it reads a property of null.

php
$isRead = $notification->checkReadOrNot();