HasBody
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
Set a formatter instance for this model.
No description
Relationship with the users who were mentioned in the body.
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.
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.