›
byrcsc/laravel-mentions · 1.x
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.
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.
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.
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.
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.
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.