class Post 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 array $customCasts from AbstractModel
static array $defaults from AbstractModel
static protected array<class-string,array<string,string>> $castsCache Resolved casts, keyed by model class. 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 array $pendingEvents from EventGeneratorTrait
static protected array $visibilityScopers from ScopeVisibilityTrait
protected $table
protected $casts
static protected Post>> $models A map of post types, as specified in the `type` column, to their classes.
string|null $type
int $id
int $discussion_id
int|Expression $number
Carbon $created_at
int|null $user_id
string|null $content
Carbon|null $edited_at
int|null $edited_user_id
Carbon|null $hidden_at
int|null $hidden_user_id
string $ip_address
bool $is_private
Discussion|null $discussion
User|null $user
User|null $editedUser
User|null $hiddenUser

Methods

static 
boot()

No description

__construct(array $attributes = [])

No description

array
getCasts()

No description

static void
flushCastsCache()

Discard the resolved casts, so that newly registered ones are picked up.

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

No description

array
releaseEvents()

Return and reset all pending events.

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

No description

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

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

static Builder
whereVisibleTo(User $user)

No description

bool
isVisibleTo(User $user)

Determine whether this post is visible to the given user.

Builder
scopeWhereVisibleToInDiscussion(Builder $query, User $actor, Discussion $discussion)

Scope a query over one discussion's posts to those visible to the user, where the caller has already established that the DISCUSSION is visible.

BelongsTo
discussion()

No description

BelongsTo
user()

No description

BelongsTo
editedUser()

No description

BelongsTo
hiddenUser()

No description

Builder
scopeAllTypes(Builder $query)

Get all posts, regardless of their type, by removing the `RegisteredTypesScope` global scope constraints applied on this model.

Post|object
newFromBuilder(array $attributes = [], string|null $connection = null)

Create a new model instance according to the post's type.

static array
getModels()

No description

static void
setModel(string $type, string $model)

No description

Details

static boot()

__construct(array $attributes = [])

Parameters

array $attributes

array getCasts()

Return Value

array

static void flushCastsCache()

Discard the resolved casts, so that newly registered ones are picked up.

Return Value

void

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

Parameters

object $event

Return Value

void

array releaseEvents()

Return and reset all pending events.

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

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

Parameters

Builder $query
User $actor
string $ability

Return Value

Builder

static Builder whereVisibleTo(User $user)

Parameters

User $user

Return Value

Builder

bool isVisibleTo(User $user)

Determine whether this post is visible to the given user.

Parameters

User $user

Return Value

bool

Builder scopeWhereVisibleToInDiscussion(Builder $query, User $actor, Discussion $discussion)

Scope a query over one discussion's posts to those visible to the user, where the caller has already established that the DISCUSSION is visible.

Applies the same registered `view` scopers as whereVisibleTo(), but lets scopers implementing {\Flarum\Post\Access\ScopesPostVisibilityWithinDiscussion} take their fast path: discussion-level access checks are evaluated once in PHP instead of as per-row subqueries, whose cost grows with the size of the discussion. Only meaningful when the query is restricted to the given discussion's posts.

Parameters

Builder $query
User $actor
Discussion $discussion

Return Value

Builder

BelongsTo discussion()

Return Value

BelongsTo

BelongsTo user()

Return Value

BelongsTo

BelongsTo editedUser()

Return Value

BelongsTo

BelongsTo hiddenUser()

Return Value

BelongsTo

Builder scopeAllTypes(Builder $query)

Get all posts, regardless of their type, by removing the `RegisteredTypesScope` global scope constraints applied on this model.

Parameters

Builder $query

Return Value

Builder

Post|object newFromBuilder(array $attributes = [], string|null $connection = null)

Create a new model instance according to the post's type.

Parameters

array $attributes
string|null $connection

Return Value

Post|object

static array getModels()

Return Value

array

static void setModel(string $type, string $model)

Parameters

string $type
string $model

Return Value

void