class Post extends Model (View source)

Traits

Methods to make a model "followable" per user.

Methods to give a model a formatted text body.

Methods to manage reactions on a model.

Methods to give a model per-user state.

Trait for models that notifications can be about.

SoftDeletes

Constants

UPDATED_AT

Properties

static protected $unguarded from  Model
Collection read-only $followedBy from  Followable
Collection read-only $ignoredBy from  Followable
static protected Formatter[] $formatters from  UsesFormatter
string $body

The original unformatted version of the body.

from  HasBody
string $parsed_body

The intermediary parsed XML document.

from  HasBody
HtmlString read-only $body_html

The formatted HTML version of the body for the current user.

from  HasBody
string read-only $body_text

The parsed body with formatting removed.

from  HasBody
Collection read-only $mentions from  HasBody
Collection read-only $attachments from  HasBody
protected $casts
int $id
int $channel_id
null|int $user_id
null|string $title
null|string $slug
null|Carbon $created_at
null|Carbon $edited_at
null|Carbon $deleted_at
null|Carbon $last_activity_at
int $comment_count
int $score
bool $is_locked
null|int $answer_id
bool $is_pinned
Channel read-only $channel
null|User read-only $user
Collection read-only $comments
Collection read-only $unreadComments
Collection read-only $tags
null|Comment read-only $lastComment
null|PostUser read-only $userState
null|Comment read-only $answer
string read-only $url
string read-only $edit_url
string read-only $unread_url
null|int read-only $unread_comments_count

Methods

getConnectionName()

No description

from  Model
BelongsToMany
followedBy()

Relationship with all users who are following this model.

BelongsToMany
ignoredBy()

Relationship with all users who are ignoring this model.

void
scopeFollowing(Builder $query)

Find only models that the current user is following.

void
scopeIgnoring(Builder $query)

Find only models that the current user is ignoring.

void
setNotifications(string|null $value)

Save the current user's notification preference for this model.

void
follow()

Follow this model for the current user.

void
unfollow()

Unfollow this model for the current user.

void
ignore()

Ignore this model for the current user.

void
unignore()

Unignore this model for the current user.

bool
isFollowed()

Whether the current user is following this model.

bool
isIgnored()

Whether the current user is ignoring this model.

HtmlString|string
format(string $attribute, User $user = null)

Render an attribute as HTML for the given user.

static Formatter
getFormatter(string $attribute)

Set a formatter instance for this model.

static void
setFormatter(string $attribute, Formatter $formatter)

Set a formatter instance for this model.

getAttribute($key)

No description

setAttribute($key, $value)

No description

static void
bootHasBody()

No description

from  HasBody
MorphToMany
mentions()

Relationship with the users who were mentioned in the body.

from  HasBody
MorphToMany
attachments()

Relationship with the uploads that were attached in the body.

from  HasBody
MorphMany
reactions()

Relationship with the reactions for this model.

reactionsSummary()

Relationship with a summary of the reactions for this model.

ReactionSet|null
reactionSet()

No description

recalculateScore()

Recalculate the score from the reactions.

HasOne
userState(User $user = null)

Relationship with the state record for a user.

loadUserState(User $user)

Load the userState relationship for the given user.

static void
bootNotificationContent()

No description

MorphMany
notifications()

Relationship with the notifications about this model.

MorphMany
groupedNotifications()

Relationship with the notifications grouped by this model.

static 
booting()

No description

void
usersWereMentioned(Collection $users)

Update the user state for any users mentioned in this post.

scopeUnread(Builder $query)

Query posts that are unread for the current user.

void
scopeWithUnreadCommentsCount(Builder $query)

Scope to select count of comments that are unread.

BelongsTo
channel()

Relationship with the post's channel.

BelongsTo
user()

Relationship with the post's author.

HasMany
comments()

Relationship with the post's comments.

HasOne
lastComment()

Relationship with the post's most recent comment.

BelongsTo
answer()

Relationship with the post's answer comment.

BelongsToMany
tags()

Relationship with the post's tags.

string
urlAtIndex(int $index = 0)

Generate a URL for a particular comment index in this post.

markAsEdited()

Mark this post as having been edited just now.

refreshCommentMetadata()

Refresh the metadata about this post's comments.

bool
isUnread()

Determine whether this post contains any new activity for the current user.

bool
isRead()

Determine whether this post has been fully read by the current user.

bool
isNew()

Determine whether this post has never before been seen by the current user.

array
streamUpdated()

Get the Turbo Streams that should be sent when this post is updated.

array
streamRemoved()

Get the Turbo Streams that should be sent when this post is removed.

int
getPerPage()

No description

string
getRouteKey()

No description

resolveRouteBinding($value, $field = null)

No description

Attribute
url()

No description

Attribute
editUrl()

No description

Attribute
unreadUrl()

No description

string
reactionsUrl(ReactionType $reactionType)

No description

Details

getConnectionName()

No description

BelongsToMany followedBy()

Relationship with all users who are following this model.

Return Value

BelongsToMany

BelongsToMany ignoredBy()

Relationship with all users who are ignoring this model.

Return Value

BelongsToMany

void scopeFollowing(Builder $query)

Find only models that the current user is following.

Parameters

Builder $query

Return Value

void

void scopeIgnoring(Builder $query)

Find only models that the current user is ignoring.

Parameters

Builder $query

Return Value

void

protected void setNotifications(string|null $value)

Save the current user's notification preference for this model.

Parameters

string|null $value

Return Value

void

void follow()

Follow this model for the current user.

Return Value

void

void unfollow()

Unfollow this model for the current user.

Return Value

void

void ignore()

Ignore this model for the current user.

Return Value

void

void unignore()

Unignore this model for the current user.

Return Value

void

bool isFollowed()

Whether the current user is following this model.

Return Value

bool

bool isIgnored()

Whether the current user is ignoring this model.

Return Value

bool

HtmlString|string format(string $attribute, User $user = null)

Render an attribute as HTML for the given user.

Parameters

string $attribute
User $user

Return Value

HtmlString|string

static Formatter getFormatter(string $attribute)

Set a formatter instance for this model.

Parameters

string $attribute

Return Value

Formatter

static void setFormatter(string $attribute, Formatter $formatter)

Set a formatter instance for this model.

Parameters

string $attribute
Formatter $formatter

Return Value

void

getAttribute($key)

No description

Parameters

$key

setAttribute($key, $value)

No description

Parameters

$key
$value

static void bootHasBody()

No description

Return Value

void

MorphToMany mentions()

Relationship with the users who were mentioned in the body.

Return Value

MorphToMany

MorphToMany attachments()

Relationship with the uploads that were attached in the body.

Return Value

MorphToMany

MorphMany reactions()

Relationship with the reactions for this model.

Return Value

MorphMany

ReactionsSummaryRelation reactionsSummary()

Relationship with a summary of the reactions for this model.

This is less expensive to load than all of the actual reactions.

ReactionSet|null reactionSet()

No description

Return Value

ReactionSet|null

Reactable recalculateScore()

Recalculate the score from the reactions.

Return Value

Reactable

HasOne userState(User $user = null)

Relationship with the state record for a user.

Defaults to the current user when no user is specified, as is the case when eager-loading the relationship.

The model representing the user state table is derived by appending User to the parent model name (eg. PostUser). Alternatively, it can be specified by setting the userStateModel property.

Parameters

User $user

Return Value

HasOne

HasUserState loadUserState(User $user)

Load the userState relationship for the given user.

Parameters

User $user

Return Value

HasUserState

static void bootNotificationContent()

No description

Return Value

void

MorphMany notifications()

Relationship with the notifications about this model.

Return Value

MorphMany

MorphMany groupedNotifications()

Relationship with the notifications grouped by this model.

Return Value

MorphMany

static booting()

No description

void usersWereMentioned(Collection $users)

Update the user state for any users mentioned in this post.

Parameters

Collection $users

Return Value

void

scopeUnread(Builder $query)

Query posts that are unread for the current user.

Parameters

Builder $query

void scopeWithUnreadCommentsCount(Builder $query)

Scope to select count of comments that are unread.

Parameters

Builder $query

Return Value

void

BelongsTo channel()

Relationship with the post's channel.

Return Value

BelongsTo

BelongsTo user()

Relationship with the post's author.

Return Value

BelongsTo

HasMany comments()

Relationship with the post's comments.

Return Value

HasMany

HasOne lastComment()

Relationship with the post's most recent comment.

Return Value

HasOne

BelongsTo answer()

Relationship with the post's answer comment.

Return Value

BelongsTo

BelongsToMany tags()

Relationship with the post's tags.

Return Value

BelongsToMany

string urlAtIndex(int $index = 0)

Generate a URL for a particular comment index in this post.

Parameters

int $index

Return Value

string

Post markAsEdited()

Mark this post as having been edited just now.

Return Value

Post

Post refreshCommentMetadata()

Refresh the metadata about this post's comments.

Return Value

Post

bool isUnread()

Determine whether this post contains any new activity for the current user.

Return Value

bool

bool isRead()

Determine whether this post has been fully read by the current user.

Return Value

bool

bool isNew()

Determine whether this post has never before been seen by the current user.

Return Value

bool

array streamUpdated()

Get the Turbo Streams that should be sent when this post is updated.

Return Value

array

array streamRemoved()

Get the Turbo Streams that should be sent when this post is removed.

Return Value

array

int getPerPage()

No description

Return Value

int

string getRouteKey()

No description

Return Value

string

resolveRouteBinding($value, $field = null)

No description

Parameters

$value
$field

protected Attribute url()

No description

Return Value

Attribute

protected Attribute editUrl()

No description

Return Value

Attribute

protected Attribute unreadUrl()

No description

Return Value

Attribute

string reactionsUrl(ReactionType $reactionType)

No description

Parameters

ReactionType $reactionType

Return Value

string