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 $customCasts from AbstractModel
static $defaults from AbstractModel
protected $tableAlias <p>An alias for the table name, used in queries.</p> from AbstractModel
protected $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 $casts
protected $observables
static protected $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
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
bool $is_private
UserState|null $state
Collection $posts
Collection $comments
Collection $participants
Post|null $firstPost
User|null $user
Post|null $lastPost
User|null $lastPostedUser
Collection $readers

Methods

static 
boot()

No description

__construct(array $attributes = [])

No description

array
getCasts()

No description

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

array
releaseAfterSaveCallbacks()

No description

array
releaseAfterDeleteCallbacks()

No description

__call($method, $parameters)

No description

newModelQuery()

No description

qualifyColumn($column)

No description

mixed
withTableAlias(callable $callback)

No description

newCollection(array $models = [])

No description

__sleep()

No description

void
raise(object $event)

No description

array
releaseEvents()

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

static void
registerVisibilityScoper(callable $scoper, string|null $ability = null)

No description

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

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

static Builder
whereVisibleTo(User $user)

No description

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

No description

rename(string $title)

No description

hide(User|null $actor = null)

No description

restore()

No description

setFirstPost(Post $post)

No description

setLastPost(Post $post)

No description

refreshLastPost()

No description

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

No description

HasMany
comments()

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

No description

BelongsTo
user()

No description

BelongsTo
lastPost()

No description

BelongsTo
lastPostedUser()

No description

BelongsTo
mostRelevantPost()

No description

BelongsToMany
readers()

No description

HasOne
state(User|null $user = null)

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

stateFor(User $user)

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

static void
setStateUser(User $user)

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

void
setTitleAttribute(string $title)

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

Details

static boot()

__construct(array $attributes = [])

Parameters

array $attributes

array getCasts()

Return Value

array

getAttribute($key)

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

Parameters

$key

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

array releaseAfterSaveCallbacks()

Return Value

array

array releaseAfterDeleteCallbacks()

Return Value

array

__call($method, $parameters)

Parameters

$method
$parameters

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 raise(object $event)

Parameters

object $event

Return Value

void

array releaseEvents()

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

Return Value

array

static void registerVisibilityScoper(callable $scoper, string|null $ability = null)

Parameters

callable $scoper
string|null $ability

Return Value

void

Builder 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

Return Value

Builder

static Builder whereVisibleTo(User $user)

Parameters

User $user

Return Value

Builder

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

Parameters

string $title
User $user

Return Value

Discussion

Discussion rename(string $title)

Parameters

string $title

Return Value

Discussion

Discussion hide(User|null $actor = null)

Parameters

User|null $actor

Return Value

Discussion

Discussion restore()

Return Value

Discussion

Discussion setFirstPost(Post $post)

Parameters

Post $post

Return Value

Discussion

Discussion setLastPost(Post $post)

Parameters

Post $post

Return Value

Discussion

Discussion refreshLastPost()

Return Value

Discussion

Discussion refreshCommentCount()

Return Value

Discussion

Discussion refreshParticipantCount()

Return Value

Discussion

MergeableInterface 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

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

Return Value

HasMany

HasMany comments()

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

Return Value

BelongsTo

BelongsTo user()

Return Value

BelongsTo

BelongsTo lastPost()

Return Value

BelongsTo

BelongsTo lastPostedUser()

Return Value

BelongsTo

BelongsTo mostRelevantPost()

Return Value

BelongsTo

BelongsToMany readers()

Return Value

BelongsToMany

HasOne state(User|null $user = null)

<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|null $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 void setStateUser(User $user)

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

Parameters

User $user

Return Value

void

protected void setTitleAttribute(string $title)

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

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

Parameters

string $title

Return Value

void