class Notification extends AbstractModel

Models a notification record in the database.

A notification record is associated with a user, and shows up in their notification list. A notification indicates that something has happened that the user should know about, like if a user's discussion was renamed by someone else.

Each notification record has a type. The type determines how the record looks in the notifications list, and what subject is associated with it. For example, the 'discussionRenamed' notification type represents that someone renamed a user's discussion. Its subject is a discussion, of which the ID is stored in the subject_id column.

Properties

bool $timestamps Indicates if the model should be timestamped. Turn off by default. from AbstractModel
protected callable[] $afterSaveCallbacks An array of callbacks to be run once after the model is saved. from AbstractModel
protected callable[] $afterDeleteCallbacks An array of callbacks to be run once after the model is deleted. from AbstractModel
protected $table {@inheritdoc}
protected $dates {@inheritdoc}
static protected array $subjectModels A map of notification types and the model classes to use for their subjects. For example, the 'discussionRenamed' notification type, which represents that a user's discussion was renamed, has the subject model class 'Flarum\Core\Discussion'.
int $id
int $user_id
int|null $sender_id
string $type
int|null $subject_id
mixed|null $data
Carbon $time
bool $is_read
bool $is_deleted
User|null $user
User|null $sender
AbstractModel|null $subject

Methods

static 
boot()

{@inheritdoc}

array
getDates()

Get the attributes that should be converted to dates.

mixed
getAttribute(string $key)

Get an attribute from the model. If nothing is found, attempt to load a custom relation method with this key.

mixed
getCustomRelation(string $name)

Get a custom relation object.

void
afterSave(callable $callback)

Register a callback to be run once after the model is saved.

void
afterDelete(callable $callback)

Register a callback to be run once after the model is deleted.

callable[]
releaseAfterSaveCallbacks()

No description

callable[]
releaseAfterDeleteCallbacks()

No description

__call($method, $arguments)

{@inheritdoc}

void
read()

Mark a notification as read.

mixed
getDataAttribute(string $value)

When getting the data attribute, unserialize the JSON stored in the database into a plain array.

setDataAttribute(mixed $value)

When setting the data attribute, serialize it into JSON for storage in the database.

string|null
getSubjectModelAttribute()

Get the subject model for this notification record by looking up its type in our subject model map.

BelongsTo
user()

Define the relationship with the notification's recipient.

BelongsTo
sender()

Define the relationship with the notification's sender.

MorphTo
subject()

Define the relationship with the notification's subject.

static array
getSubjectModels()

Get the type-to-subject-model map.

static void
setSubjectModel(string $type, string $subjectModel)

Set the subject model for the given notification type.

Details

static boot()

{@inheritdoc}

array getDates()

Get the attributes that should be converted to dates.

Return Value

array

mixed getAttribute(string $key)

Get an attribute from the model. If nothing is found, attempt to load a custom relation method with this key.

Parameters

string $key

Return Value

mixed

protected mixed getCustomRelation(string $name)

Get a custom relation object.

Parameters

string $name

Return Value

mixed

void afterSave(callable $callback)

Register a callback to be run once after the model is saved.

Parameters

callable $callback

Return Value

void

void afterDelete(callable $callback)

Register a callback to be run once after the model is deleted.

Parameters

callable $callback

Return Value

void

callable[] releaseAfterSaveCallbacks()

Return Value

callable[]

callable[] releaseAfterDeleteCallbacks()

Return Value

callable[]

__call($method, $arguments)

{@inheritdoc}

Parameters

$method
$arguments

void read()

Mark a notification as read.

Return Value

void

mixed getDataAttribute(string $value)

When getting the data attribute, unserialize the JSON stored in the database into a plain array.

Parameters

string $value

Return Value

mixed

setDataAttribute(mixed $value)

When setting the data attribute, serialize it into JSON for storage in the database.

Parameters

mixed $value

string|null getSubjectModelAttribute()

Get the subject model for this notification record by looking up its type in our subject model map.

Return Value

string|null

BelongsTo user()

Define the relationship with the notification's recipient.

Return Value

BelongsTo

BelongsTo sender()

Define the relationship with the notification's sender.

Return Value

BelongsTo

MorphTo subject()

Define the relationship with the notification's subject.

Return Value

MorphTo

static array getSubjectModels()

Get the type-to-subject-model map.

Return Value

array

static void setSubjectModel(string $type, string $subjectModel)

Set the subject model for the given notification type.

Parameters

string $type The notification type.
string $subjectModel The class name of the subject model for that type.

Return Value

void