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

Parsing text.

See which handles or target IDs the package reads from saved text.

Before the package can find a model, it must decide which parts of the saved text are mentions. A parser performs that text-only step. It does not query the database.

Plain-text parsing

The default RegexMentionParser looks for the configured trigger followed by the configured handle pattern:

'trigger' => '@',
'handle_pattern' => '[A-Za-z0-9_]+',

With those defaults, this text produces three candidates:

@start, hello @jane! Please ask @team_1.

The raw values are @start, @jane, and @team_1. Candidate handles omit the trigger.

The parser uses a negative lookbehind before the trigger. It does not treat the domain in jane@example.com as a mention under the default pattern.

Duplicate behavior

The regex parser removes exact duplicate handles within one string. Handle case is part of that first-stage comparison:

$parser->parse('@Jane, @Jane, and @jane');

This returns candidates for Jane and jane. Resolution is case insensitive, and synchronization later collapses candidates that point to the same target.

Markup parsing

MarkupMentionParser reads any element with a non-empty data-mention-id:

<span data-mention-id="42" data-mention-type="users">@jane</span>

The parser accepts single or double quotes and any attribute order. It keeps IDs as strings, including UUIDs and ULIDs.

The parser deduplicates markup candidates by the combination of data-mention-type and data-mention-id. It passes malformed HTML through DOMDocument, so the repaired text may differ from the input.

Empty and non-string attributes

Both shipped parsers return an empty array for an empty string. The parser contract accepts string, not null.

HasMentions converts a null or non-string model attribute to an empty string before calling the parser.

Invalid parser configuration

The regex parser throws InvalidArgumentException when the trigger or handle pattern is empty. It also throws when handle_pattern is not a valid regular expression fragment.

What it does not do

  • Parsing does not query, authorize, or persist target models.
  • The regex parser does not strip HTML before matching.
  • The markup parser does not compare visible text with the target model.
  • Neither parser sanitizes text or HTML.

What to read next

  • Resolving targets for the database stage after parsing.
  • Use markup mentions to configure an HTML source model.
  • Configuration to change the trigger and handle pattern.
PreviousMention recordsNextResolving targets
View source

On this page

  1. Plain-text parsing
  2. Duplicate behavior
  3. Markup parsing
  4. Empty and non-string attributes
  5. Invalid parser configuration
  6. What it does not do
  7. What to read next