trait HasBody (View source)

Methods to give a model a formatted text body.

This trait assumes a body column exists on the model. When this attribute is set on the model, the content will be parsed into an XML document by the Formatter, and stored in the database in this form. When the body attribute is retrieved, it is unparsed back into the original plain-text version.

This trait also adds a mentions relationship to store a list of the users mentioned in the body using the @ prefix. This relationship can then be loaded before the body is rendered so that the Formatter can substitute in the most up-to-date usernames.

Traits

Properties

static protected Formatter[] $formatters from  UsesFormatter
string $body

The original unformatted version of the body.

string $parsed_body

The intermediary parsed XML document.

HtmlString read-only $body_html

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

string read-only $body_text

The parsed body with formatting removed.

Collection read-only $mentions
Collection read-only $attachments

Methods

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

MorphToMany
mentions()

Relationship with the users who were mentioned in the body.

MorphToMany
attachments()

Relationship with the uploads that were attached in the body.

Details

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