›
›
›
  1. docs
  2. ›
  3. byrcsc/laravel-mentions
1.x
Browse documentationOpenClose

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Mention records
  • Parsing text
  • Resolving targets
  • Synchronization

Operations

  • Scan multiple attributes
  • Use markup mentions
  • Mention groups
  • Querying mentions
  • React to lifecycle events
  • Control synchronization
  • Extend the package

Reference

  • Configuration
  • Public API
  • Published assets
  • Testing
  • Troubleshooting

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Mention records
  • Parsing text
  • Resolving targets
  • Synchronization

Operations

  • Scan multiple attributes
  • Use markup mentions
  • Mention groups
  • Querying mentions
  • React to lifecycle events
  • Control synchronization
  • Extend the package

Reference

  • Configuration
  • Public API
  • Published assets
  • Testing
  • Troubleshooting

byrcsc/laravel-mentions · 1.x

Scan multiple attributes.

Read mention text from more than one attribute on the same source model.

If mentions can appear in more than one column, list every column on the source model. The package reads them together and stores each target once, even when the same handle appears in several columns.

List the attributes

Add each text column to $mentionableAttributes:

use Byrcsc\Mentions\Concerns\HasMentions;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasMentions;

    /** @var list<string> */
    protected array $mentionableAttributes = [
        'summary',
        'body',
        'editor_notes',
    ];
}

If @jane appears in both summary and body, the source still stores one mention row for Jane.

Removing Jane from one attribute keeps the row while another configured attribute still mentions her.

Choose attributes at runtime

Override mentionableAttributes() when the columns depend on model state:

/** @return list<string> */
protected function mentionableAttributes(): array
{
    return $this->is_internal
        ? ['body', 'internal_notes']
        : ['body'];
}

The package calls the method during each synchronization. Return attribute names as strings.

Null and non-string values

HasMentions passes string values to the parser. A null, integer, array, cast object, or other non-string value becomes an empty string for that sync.

If a cast returns a value object, expose the underlying text through a string attribute or override mentionableAttributes() to select a stored string column.

Use one parser per model

One synchronization selects one parser for all configured attributes. Do not mix plain text and HTML columns on the same source model unless a custom parser understands both formats.

Separate the formats into different source models, or write a custom parser that applies a defined rule to each input string.

What to read next

  • Parsing text for the input rules applied to each attribute.
  • Control synchronization to run the combined diff explicitly.
  • Extend the package to register a parser for another format.
PreviousSynchronizationNextUse markup mentions
View source

On this page

  1. List the attributes
  2. Choose attributes at runtime
  3. Null and non-string values
  4. Use one parser per model
  5. What to read next