class Discussion extends AbstractModel

Traits

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
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 <p>An array of posts that have been modified during this request.</p>
protected array $dates <p>The attributes that should be mutated to dates.</p>
protected array $casts <p>The attributes that should be cast to native types.</p>
static protected User $stateUser <p>The user for which the state relationship should be loaded.</p>
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()

<p>Boot the model.</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>

raise(mixed $event)

<p>Raise a new event.</p>

array
releaseEvents()

<p>Return and reset all pending events.</p>

static 
registerVisibilityScoper($scoper, $ability = null)

No description

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

<p>Scope a query to only include records that are visible to a user.</p>

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

<p>Start a new discussion. Raises the DiscussionWasStarted event.</p>

$this
rename(string $title)

<p>Rename the discussion. Raises the DiscussionWasRenamed event.</p>

$this
hide(User $actor = null)

<p>Hide the discussion.</p>

$this
restore()

<p>Restore the discussion.</p>

$this
setFirstPost(Post $post)

<p>Set the discussion's first post details.</p>

$this
setLastPost(Post $post)

<p>Set the discussion's last post details.</p>

$this
refreshLastPost()

<p>Refresh a discussion's last post details.</p>

$this
refreshCommentCount()

<p>Refresh the discussion's comment count.</p>

$this
refreshParticipantCount()

<p>Refresh the discussion's participant count.</p>

mergePost(MergeableInterface $post)

<p>Save a post, attempting to merge it with the discussion's last post.</p>

array
getModifiedPosts()

<p>Get the posts that have been modified during this request.</p>

HasMany
posts()

<p>Define the relationship with the discussion's posts.</p>

HasMany
comments()

<p>Define the relationship with the discussion's publicly-visible comments.</p>

Builder
participants()

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

BelongsTo
firstPost()

<p>Define the relationship with the discussion's first post.</p>

BelongsTo
user()

<p>Define the relationship with the discussion's author.</p>

BelongsTo
lastPost()

<p>Define the relationship with the discussion's last post.</p>

BelongsTo
lastPostedUser()

<p>Define the relationship with the discussion's most recent author.</p>

BelongsTo
mostRelevantPost()

<p>Define the relationship with the discussion's most relevant post.</p>

BelongsToMany
readers()

<p>Define the relationship with the discussion's readers.</p>

HasOne
state(User $user = null)

<p>Define the relationship with the discussion's state for a particular user.</p>

stateFor(User $user)

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

static 
setStateUser(User $user)

<p>Set the user for which the state relationship should be loaded.</p>

setTitleAttribute(string $title)

<p>Set the discussion title.</p>

Details

static boot()

<p>Boot the model.</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

raise(mixed $event)

<p>Raise a new event.</p>

Parameters

mixed $event

array releaseEvents()

<p>Return and reset all pending events.</p>

Return Value

array

static registerVisibilityScoper($scoper, $ability = null)

Parameters

$scoper
$ability

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

<p>Scope a query to only include records that are visible to a user.</p>

Parameters

Builder $query
User $actor
string $ability

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

<p>Start a new discussion. Raises the DiscussionWasStarted event.</p>

Parameters

string $title
User $user

Return Value

Discussion

$this rename(string $title)

<p>Rename the discussion. Raises the DiscussionWasRenamed event.</p>

Parameters

string $title

Return Value

$this

$this hide(User $actor = null)

<p>Hide the discussion.</p>

Parameters

User $actor

Return Value

$this

$this restore()

<p>Restore the discussion.</p>

Return Value

$this

$this setFirstPost(Post $post)

<p>Set the discussion's first post details.</p>

Parameters

Post $post

Return Value

$this

$this setLastPost(Post $post)

<p>Set the discussion's last post details.</p>

Parameters

Post $post

Return Value

$this

$this refreshLastPost()

<p>Refresh a discussion's last post details.</p>

Return Value

$this

$this refreshCommentCount()

<p>Refresh the discussion's comment count.</p>

Return Value

$this

$this refreshParticipantCount()

<p>Refresh the discussion's participant count.</p>

Return Value

$this

Post mergePost(MergeableInterface $post)

<p>Save a post, attempting to merge it with the discussion's last post.</p>

<p>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.)</p>

Parameters

MergeableInterface $post <p>The post to save.</p>

Return Value

Post <p>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.</p>

array getModifiedPosts()

<p>Get the posts that have been modified during this request.</p>

Return Value

array

HasMany posts()

<p>Define the relationship with the discussion's posts.</p>

Return Value

HasMany

HasMany comments()

<p>Define the relationship with the discussion's publicly-visible comments.</p>

Return Value

HasMany

Builder participants()

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

Return Value

Builder

BelongsTo firstPost()

<p>Define the relationship with the discussion's first post.</p>

Return Value

BelongsTo

BelongsTo user()

<p>Define the relationship with the discussion's author.</p>

Return Value

BelongsTo

BelongsTo lastPost()

<p>Define the relationship with the discussion's last post.</p>

Return Value

BelongsTo

BelongsTo lastPostedUser()

<p>Define the relationship with the discussion's most recent author.</p>

Return Value

BelongsTo

BelongsTo mostRelevantPost()

<p>Define the relationship with the discussion's most relevant post.</p>

Return Value

BelongsTo

BelongsToMany readers()

<p>Define the relationship with the discussion's readers.</p>

Return Value

BelongsToMany

HasOne state(User $user = null)

<p>Define the relationship with the discussion's state for a particular user.</p>

<p>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.</p>

Parameters

User $user

Return Value

HasOne

See also

Discussion::setStateUser

UserState stateFor(User $user)

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

Parameters

User $user

Return Value

UserState

static setStateUser(User $user)

<p>Set the user for which the state relationship should be loaded.</p>

Parameters

User $user

protected setTitleAttribute(string $title)

<p>Set the discussion title.</p>

<p>This automatically creates a matching slug for the discussion.</p>

Parameters

string $title