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

static 
boot()

No description

__construct(array $attributes = [])

No description

array
getCasts()

No description

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.

array
releaseAfterSaveCallbacks()

No description

array
releaseAfterDeleteCallbacks()

No description

newModelQuery()

No description

qualifyColumn($column)

No description

mixed
withTableAlias(callable $callback)

No description

newCollection(array $models = [])

No description

__sleep()

No description

void
read()

No description

string|null
getSubjectModelAttribute()

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

BelongsTo
user()

No description

BelongsTo
fromUser()

No description

MorphTo
subject()

No description

Builder
scopeWhereSubjectVisibleTo(Builder $query, User $actor)

Scope the query to include only notifications whose subjects are visible to the given user.

Builder
scopeWhereSubject(Builder $query, AbstractModel $model)

Scope the query to include only notifications that have the given subject.

Builder
scopeWhereSubjectModel(Builder $query, string $class)

Scope the query to include only notification types that use the given subject model.

Builder
scopeMatchingBlueprint(Builder $query, BlueprintInterface $blueprint)

Scope the query to find all records matching the given blueprint.

static void
notify(array $recipients, BlueprintInterface|AlertableInterface $blueprint)

Send notifications to the given recipients.

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.

static array
getBlueprintAttributes(BlueprintInterface $blueprint)

No description

void
static() $Illuminate\Database\Eloquent\Builder matchingBlueprint(BlueprintInterface $blueprint)

No description

Details

static boot()

__construct(array $attributes = [])

Parameters

array $attributes

array getCasts()

Return Value

array

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

array releaseAfterSaveCallbacks()

Return Value

array

array releaseAfterDeleteCallbacks()

Return Value

array

newModelQuery()

qualifyColumn($column)

Parameters

$column

mixed withTableAlias(callable $callback)

Parameters

callable $callback

Return Value

mixed

Collection newCollection(array $models = [])

Parameters

array $models

Return Value

Collection

__sleep()

void read()

Return Value

void

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()

Return Value

BelongsTo

BelongsTo fromUser()

Return Value

BelongsTo

MorphTo subject()

Return Value

MorphTo

Builder scopeWhereSubjectVisibleTo(Builder $query, User $actor)

Scope the query to include only notifications whose subjects are visible to the given user.

Parameters

Builder $query
User $actor

Return Value

Builder

Builder scopeWhereSubject(Builder $query, AbstractModel $model)

Scope the query to include only notifications that have the given subject.

Parameters

Builder $query
AbstractModel $model

Return Value

Builder

Builder scopeWhereSubjectModel(Builder $query, string $class)

Scope the query to include only notification types that use the given subject model.

Parameters

Builder $query
string $class

Return Value

Builder

Builder scopeMatchingBlueprint(Builder $query, BlueprintInterface $blueprint)

Scope the query to find all records matching the given blueprint.

Parameters

Builder $query
BlueprintInterface $blueprint

Return Value

Builder

static void notify(array $recipients, BlueprintInterface|AlertableInterface $blueprint)

Send notifications to the given recipients.

Parameters

array $recipients
BlueprintInterface|AlertableInterface $blueprint

Return Value

void

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

static protected array getBlueprintAttributes(BlueprintInterface $blueprint)

Parameters

BlueprintInterface $blueprint

Return Value

array

void static() $Illuminate\Database\Eloquent\Builder matchingBlueprint(BlueprintInterface $blueprint)

Parameters

) $Illuminate\Database\Eloquent\Builder matchingBlueprint(BlueprintInterface $blueprint

Return Value

void