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 | <p>Indicates if the model should be timestamped. Turn off by default.</p> | from AbstractModel | |
protected callable[] | $afterSaveCallbacks | <p>An array of callbacks to be run once after the model is saved.</p> | from AbstractModel | |
protected callable[] | $afterDeleteCallbacks | <p>An array of callbacks to be run once after the model is deleted.</p> | from AbstractModel | |
static | $customRelations | from AbstractModel | ||
static | $dateAttributes | from AbstractModel | ||
static | $defaults | from AbstractModel | ||
int | $id | |||
protected array | $dates | <p>The attributes that should be mutated to dates.</p> | ||
static protected array | $subjectModels | <p>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\Discussion\Discussion'.</p> | ||
int | $user_id | |||
int|null | $from_user_id | |||
string | $type | |||
int|null | $subject_id | |||
mixed|null | $data | |||
Carbon | $created_at | |||
Carbon | $read_at | |||
Carbon | $deleted_at | |||
User|null | $user | |||
User|null | $fromUser | |||
AbstractModel|Post|Discussion|null | $subject |
Methods
<p>Get an attribute from the model. If nothing is found, attempt to load a custom relation method with this key.</p>
<p>Register a callback to be run once after the model is saved.</p>
<p>Register a callback to be run once after the model is deleted.</p>
<p>When getting the data attribute, unserialize the JSON stored in the database into a plain array.</p>
<p>When setting the data attribute, serialize it into JSON for storage in the database.</p>
<p>Get the subject model for this notification record by looking up its type in our subject model map.</p>
<p>Scope the query to include only notifications whose subjects are visible to the given user.</p>
<p>Scope the query to include only notifications that have the given subject.</p>
<p>Scope the query to include only notification types that use the given subject model.</p>
<p>Scope the query to find all records matching the given blueprint.</p>
<p>Send notifications to the given recipients.</p>
<p>Set the subject model for the given notification type.</p>
Details
in AbstractModel
at
line 67
static
boot()
<p>{@inheritdoc}</p>
in AbstractModel
at
line 87
__construct(array $attributes = [])
<p>{@inheritdoc}</p>
in AbstractModel
at
line 107
array
getDates()
<p>Get the attributes that should be converted to dates.</p>
in AbstractModel
at
line 125
mixed
getAttribute(string $key)
<p>Get an attribute from the model. If nothing is found, attempt to load a custom relation method with this key.</p>
in AbstractModel
at
line 151
protected mixed
getCustomRelation(string $name)
<p>Get a custom relation object.</p>
in AbstractModel
at
line 167
void
afterSave(callable $callback)
<p>Register a callback to be run once after the model is saved.</p>
in AbstractModel
at
line 178
void
afterDelete(callable $callback)
<p>Register a callback to be run once after the model is deleted.</p>
in AbstractModel
at
line 186
callable[]
releaseAfterSaveCallbacks()
in AbstractModel
at
line 198
callable[]
releaseAfterDeleteCallbacks()
in AbstractModel
at
line 210
__call($method, $arguments)
<p>{@inheritdoc}</p>
at
line 70
void
read()
<p>Mark a notification as read.</p>
at
line 82
mixed
getDataAttribute(string|null $value)
<p>When getting the data attribute, unserialize the JSON stored in the database into a plain array.</p>
at
line 95
setDataAttribute(mixed $value)
<p>When setting the data attribute, serialize it into JSON for storage in the database.</p>
at
line 106
string|null
getSubjectModelAttribute()
<p>Get the subject model for this notification record by looking up its type in our subject model map.</p>
at
line 116
BelongsTo
user()
<p>Define the relationship with the notification's recipient.</p>
at
line 126
BelongsTo
fromUser()
<p>Define the relationship with the notification's sender.</p>
at
line 136
MorphTo
subject()
<p>Define the relationship with the notification's subject.</p>
at
line 148
Builder
scopeWhereSubjectVisibleTo(Builder $query, User $actor)
<p>Scope the query to include only notifications whose subjects are visible to the given user.</p>
at
line 182
Builder
scopeWhereSubject(Builder $query, object $model)
<p>Scope the query to include only notifications that have the given subject.</p>
at
line 196
Builder
scopeWhereSubjectModel(Builder $query, string $class)
<p>Scope the query to include only notification types that use the given subject model.</p>
at
line 212
Builder
scopeMatchingBlueprint(Builder $query, BlueprintInterface $blueprint)
<p>Scope the query to find all records matching the given blueprint.</p>
at
line 223
static
notify(array $recipients, BlueprintInterface $blueprint)
<p>Send notifications to the given recipients.</p>
at
line 243
static array
getSubjectModels()
<p>Get the type-to-subject-model map.</p>
at
line 256
static void
setSubjectModel(string $type, string $subjectModel)
<p>Set the subject model for the given notification type.</p>