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