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 array | $customCasts | from AbstractModel |
|
|
| static array | $defaults | from AbstractModel |
|
|
| protected string|null | $tableAlias | An alias for the table name, used in queries. | from AbstractModel |
|
| string[]|null | $uniqueKeys | If a model has unique keys, they should be defined here. | from AbstractModel |
|
| protected | $casts |
|
||
| static protected AbstractModel>> | $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 |
|
||
| array|null | $data |
|
||
| Carbon | $created_at |
|
||
| Carbon | $read_at |
|
||
| Carbon | $deleted_at |
|
||
| User|null | $user |
|
||
| User|null | $fromUser |
|
||
| AbstractModel|Post|Discussion|null | $subject |
|
Methods
Register a callback to be run once after the model is saved.
Register a callback to be run once after the model is deleted.
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.
No description
Details
in AbstractModel
at
line 71
static
boot()
in AbstractModel
at
line 88
__construct(array $attributes = [])
in AbstractModel
at
line 103
array
getCasts()
in AbstractModel
at
line 117
void
afterSave(callable $callback)
Register a callback to be run once after the model is saved.
in AbstractModel
at
line 125
void
afterDelete(callable $callback)
Register a callback to be run once after the model is deleted.
in AbstractModel
at
line 133
array
releaseAfterSaveCallbacks()
in AbstractModel
at
line 145
array
releaseAfterDeleteCallbacks()
in AbstractModel
at
line 157
newModelQuery()
in AbstractModel
at
line 169
qualifyColumn($column)
in AbstractModel
at
line 178
mixed
withTableAlias(callable $callback)
in AbstractModel
at
line 191
Collection
newCollection(array $models = [])
in AbstractModel
at
line 197
__sleep()
at
line 72
void
read()
at
line 81
string|null
getSubjectModelAttribute()
Get the subject model for this notification record by looking up its type in our subject model map.
at
line 86
BelongsTo
user()
at
line 91
BelongsTo
fromUser()
at
line 96
MorphTo
subject()
at
line 105
Builder
scopeWhereSubjectVisibleTo(Builder $query, User $actor)
Scope the query to include only notifications whose subjects are visible to the given user.
at
line 135
Builder
scopeWhereSubject(Builder $query, AbstractModel $model)
Scope the query to include only notifications that have the given subject.
at
line 145
Builder
scopeWhereSubjectModel(Builder $query, string $class)
Scope the query to include only notification types that use the given subject model.
at
line 157
Builder
scopeMatchingBlueprint(Builder $query, BlueprintInterface $blueprint)
Scope the query to find all records matching the given blueprint.
at
line 177
static void
notify(array $recipients, BlueprintInterface|AlertableInterface $blueprint)
Send notifications to the given recipients.
at
line 202
static array
getSubjectModels()
Get the type-to-subject-model map.
at
line 214
static void
setSubjectModel(string $type, string $subjectModel)
Set the subject model for the given notification type.