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
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 $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

static 
boot()

<p>{@inheritdoc}</p>

__construct(array $attributes = [])

<p>{@inheritdoc}</p>

array
getDates()

<p>Get the attributes that should be converted to dates.</p>

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>

mixed
getCustomRelation(string $name)

<p>Get a custom relation object.</p>

void
afterSave(callable $callback)

<p>Register a callback to be run once after the model is saved.</p>

void
afterDelete(callable $callback)

<p>Register a callback to be run once after the model is deleted.</p>

callable[]
releaseAfterSaveCallbacks()

No description

callable[]
releaseAfterDeleteCallbacks()

No description

__call($method, $arguments)

<p>{@inheritdoc}</p>

void
read()

<p>Mark a notification as read.</p>

mixed
getDataAttribute(string $value)

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

setDataAttribute(mixed $value)

<p>When setting the data attribute, serialize it into JSON for storage in the database.</p>

string|null
getSubjectModelAttribute()

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

BelongsTo
user()

<p>Define the relationship with the notification's recipient.</p>

BelongsTo
fromUser()

<p>Define the relationship with the notification's sender.</p>

MorphTo
subject()

<p>Define the relationship with the notification's subject.</p>

scopeWhereSubjectVisibleTo(Builder $query, User $actor)

<p>Scope the query to include only notifications whose subjects are visible to the given user.</p>

scopeWhereSubject(Builder $query, object $model)

<p>Scope the query to include only notifications that have the given subject.</p>

scopeWhereSubjectModel(Builder $query, string $class)

<p>Scope the query to include only notification types that use the given subject model.</p>

static array
getSubjectModels()

<p>Get the type-to-subject-model map.</p>

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

<p>Set the subject model for the given notification type.</p>

Details

static boot()

<p>{@inheritdoc}</p>

__construct(array $attributes = [])

<p>{@inheritdoc}</p>

Parameters

array $attributes

array getDates()

<p>Get the attributes that should be converted to dates.</p>

Return Value

array

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>

Parameters

string $key

Return Value

mixed

protected mixed getCustomRelation(string $name)

<p>Get a custom relation object.</p>

Parameters

string $name

Return Value

mixed

void afterSave(callable $callback)

<p>Register a callback to be run once after the model is saved.</p>

Parameters

callable $callback

Return Value

void

void afterDelete(callable $callback)

<p>Register a callback to be run once after the model is deleted.</p>

Parameters

callable $callback

Return Value

void

callable[] releaseAfterSaveCallbacks()

Return Value

callable[]

callable[] releaseAfterDeleteCallbacks()

Return Value

callable[]

__call($method, $arguments)

<p>{@inheritdoc}</p>

Parameters

$method
$arguments

void read()

<p>Mark a notification as read.</p>

Return Value

void

mixed getDataAttribute(string $value)

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

Parameters

string $value

Return Value

mixed

setDataAttribute(mixed $value)

<p>When setting the data attribute, serialize it into JSON for storage in the database.</p>

Parameters

mixed $value

string|null getSubjectModelAttribute()

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

Return Value

string|null

BelongsTo user()

<p>Define the relationship with the notification's recipient.</p>

Return Value

BelongsTo

BelongsTo fromUser()

<p>Define the relationship with the notification's sender.</p>

Return Value

BelongsTo

MorphTo subject()

<p>Define the relationship with the notification's subject.</p>

Return Value

MorphTo

scopeWhereSubjectVisibleTo(Builder $query, User $actor)

<p>Scope the query to include only notifications whose subjects are visible to the given user.</p>

Parameters

Builder $query
User $actor

scopeWhereSubject(Builder $query, object $model)

<p>Scope the query to include only notifications that have the given subject.</p>

Parameters

Builder $query
object $model

scopeWhereSubjectModel(Builder $query, string $class)

<p>Scope the query to include only notification types that use the given subject model.</p>

Parameters

Builder $query
string $class

static array getSubjectModels()

<p>Get the type-to-subject-model map.</p>

Return Value

array

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

<p>Set the subject model for the given notification type.</p>

Parameters

string $type <p>The notification type.</p>
string $subjectModel <p>The class name of the subject model for that type.</p>

Return Value

void