class Discussion extends AbstractModel

Traits

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 $pendingEvents from EventGeneratorTrait
static protected $visibilityScopers from ScopeVisibilityTrait
protected array $modifiedPosts An array of posts that have been modified during this request.
protected array $dates The attributes that should be mutated to dates.
protected array $casts The attributes that should be cast to native types.
static protected User $stateUser The user for which the state relationship should be loaded.
int $id
string $title
string $slug
int $comment_count
int $participant_count
int $post_number_index
Carbon $created_at
int|null $user_id
int|null $first_post_id
Carbon|null $last_posted_at
int|null $last_posted_user_id
int|null $last_post_id
int|null $last_post_number
Carbon|null $hidden_at
int|null $hidden_user_id
UserState|null $state
Collection $posts
Collection $comments
Collection $participants
Post|null $firstPost
User|null $user
Post|null $lastPost
User|null $lastPostedUser
Collection $readers
bool $is_private

Methods

static 
boot()

Boot the model.

__construct(array $attributes = [])

{@inheritdoc}

array
getDates()

Get the attributes that should be converted to dates.

mixed
getAttribute(string $key)

Get an attribute from the model. If nothing is found, attempt to load a custom relation method with this key.

mixed
getCustomRelation(string $name)

Get a custom relation object.

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.

callable[]
releaseAfterSaveCallbacks()

No description

callable[]
releaseAfterDeleteCallbacks()

No description

__call($method, $arguments)

{@inheritdoc}

raise(mixed $event)

Raise a new event.

array
releaseEvents()

Return and reset all pending events.

static 
registerVisibilityScoper($scoper, $ability = null)

No description

scopeWhereVisibleTo(Builder $query, User $actor, string $ability = 'view')

Scope a query to only include records that are visible to a user.

static Discussion
start(string $title, User $user)

Start a new discussion. Raises the DiscussionWasStarted event.

$this
rename(string $title)

Rename the discussion. Raises the DiscussionWasRenamed event.

$this
hide(User $actor = null)

Hide the discussion.

$this
restore()

Restore the discussion.

$this
setFirstPost(Post $post)

Set the discussion's first post details.

$this
setLastPost(Post $post)

Set the discussion's last post details.

$this
refreshLastPost()

Refresh a discussion's last post details.

$this
refreshCommentCount()

Refresh the discussion's comment count.

$this
refreshParticipantCount()

Refresh the discussion's participant count.

Post
mergePost(MergeableInterface $post)

Save a post, attempting to merge it with the discussion's last post.

array
getModifiedPosts()

Get the posts that have been modified during this request.

HasMany
posts()

Define the relationship with the discussion's posts.

HasMany
comments()

Define the relationship with the discussion's publicly-visible comments.

Builder
participants()

Query the discussion's participants (a list of unique users who have posted in the discussion).

BelongsTo
firstPost()

Define the relationship with the discussion's first post.

BelongsTo
user()

Define the relationship with the discussion's author.

BelongsTo
lastPost()

Define the relationship with the discussion's last post.

BelongsTo
lastPostedUser()

Define the relationship with the discussion's most recent author.

BelongsTo
mostRelevantPost()

Define the relationship with the discussion's most relevant post.

BelongsToMany
readers()

Define the relationship with the discussion's readers.

HasOne
state(User $user = null)

Define the relationship with the discussion's state for a particular user.

stateFor(User $user)

Get the state model for a user, or instantiate a new one if it does not exist.

static 
setStateUser(User $user)

Set the user for which the state relationship should be loaded.

setTitleAttribute(string $title)

Set the discussion title.

Details

static boot()

Boot the model.

__construct(array $attributes = [])

{@inheritdoc}

Parameters

array $attributes

array getDates()

Get the attributes that should be converted to dates.

Return Value

array

mixed getAttribute(string $key)

Get an attribute from the model. If nothing is found, attempt to load a custom relation method with this key.

Parameters

string $key

Return Value

mixed

protected mixed getCustomRelation(string $name)

Get a custom relation object.

Parameters

string $name

Return Value

mixed

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

callable[] releaseAfterSaveCallbacks()

Return Value

callable[]

callable[] releaseAfterDeleteCallbacks()

Return Value

callable[]

__call($method, $arguments)

{@inheritdoc}

Parameters

$method
$arguments

raise(mixed $event)

Raise a new event.

Parameters

mixed $event

array releaseEvents()

Return and reset all pending events.

Return Value

array

static registerVisibilityScoper($scoper, $ability = null)

Parameters

$scoper
$ability

scopeWhereVisibleTo(Builder $query, User $actor, string $ability = 'view')

Scope a query to only include records that are visible to a user.

Parameters

Builder $query
User $actor
string $ability

static Discussion start(string $title, User $user)

Start a new discussion. Raises the DiscussionWasStarted event.

Parameters

string $title
User $user

Return Value

Discussion

$this rename(string $title)

Rename the discussion. Raises the DiscussionWasRenamed event.

Parameters

string $title

Return Value

$this

$this hide(User $actor = null)

Hide the discussion.

Parameters

User $actor

Return Value

$this

$this restore()

Restore the discussion.

Return Value

$this

$this setFirstPost(Post $post)

Set the discussion's first post details.

Parameters

Post $post

Return Value

$this

$this setLastPost(Post $post)

Set the discussion's last post details.

Parameters

Post $post

Return Value

$this

$this refreshLastPost()

Refresh a discussion's last post details.

Return Value

$this

$this refreshCommentCount()

Refresh the discussion's comment count.

Return Value

$this

$this refreshParticipantCount()

Refresh the discussion's participant count.

Return Value

$this

Post mergePost(MergeableInterface $post)

Save a post, attempting to merge it with the discussion's last post.

The merge logic is delegated to the new post. (As an example, a DiscussionRenamedPost will merge if adjacent to another DiscussionRenamedPost, and delete if the title has been reverted completely.)

Parameters

MergeableInterface $post The post to save.

Return Value

Post The resulting post. It may or may not be the same post as was originally intended to be saved. It also may not exist, if the merge logic resulted in deletion.

array getModifiedPosts()

Get the posts that have been modified during this request.

Return Value

array

HasMany posts()

Define the relationship with the discussion's posts.

Return Value

HasMany

HasMany comments()

Define the relationship with the discussion's publicly-visible comments.

Return Value

HasMany

Builder participants()

Query the discussion's participants (a list of unique users who have posted in the discussion).

Return Value

Builder

BelongsTo firstPost()

Define the relationship with the discussion's first post.

Return Value

BelongsTo

BelongsTo user()

Define the relationship with the discussion's author.

Return Value

BelongsTo

BelongsTo lastPost()

Define the relationship with the discussion's last post.

Return Value

BelongsTo

BelongsTo lastPostedUser()

Define the relationship with the discussion's most recent author.

Return Value

BelongsTo

BelongsTo mostRelevantPost()

Define the relationship with the discussion's most relevant post.

Return Value

BelongsTo

BelongsToMany readers()

Define the relationship with the discussion's readers.

Return Value

BelongsToMany

HasOne state(User $user = null)

Define the relationship with the discussion's state for a particular user.

If no user is passed (i.e. in the case of eager loading the 'state' relation), then the static <code>$stateUser</code> property is used.

Parameters

User $user

Return Value

HasOne

See also

\Discussion::setStateUser()

UserState stateFor(User $user)

Get the state model for a user, or instantiate a new one if it does not exist.

Parameters

User $user

Return Value

UserState

static setStateUser(User $user)

Set the user for which the state relationship should be loaded.

Parameters

User $user

protected setTitleAttribute(string $title)

Set the discussion title.

This automatically creates a matching slug for the discussion.

Parameters

string $title