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

Configuration.

The mentions configuration controls storage, syncing, parsing, and target lookup.

Publish the configuration when the package defaults do not match your models or mention format:

php artisan vendor:publish --tag="mentions-config"

The command writes config/mentions.php.

Configuration keys

KeyDefaultPurpose
modelPackage Mention classModel used for every mention record
tablementionsTable used by the model and migration
auto_synctrueRuns sync after normal Eloquent saves
default_parserregexParser name used without a model override
parsersregex and markup mappingsParser names mapped to class strings
resolversIncomplete default definitionOrdered target lookup definitions
trigger@Prefix used by the regex parser
handle_pattern[A-Za-z0-9_]+Regex fragment accepted after the prefix

The default resolver is intentionally incomplete because a reusable package cannot choose your target model. Set resolvers.default.model or replace the definition before syncing plain-text mentions.

Mention model and table

'model' => Byrcsc\Mentions\Models\Mention::class,
'table' => 'mentions',

model must be a class string that extends the package Mention model. The container binding throws InvalidArgumentException for another class.

The model reads table each time Eloquent calls getTable(). An empty or non-string value falls back to mentions. Keep the migration and runtime setting aligned.

Automatic synchronization

'auto_sync' => true,

The source trait checks for the literal boolean true. Other values disable automatic synchronization. Use a boolean in configuration instead of a string.

Parser registration

'default_parser' => 'regex',
'parsers' => [
    'regex' => Byrcsc\Mentions\Parsers\RegexMentionParser::class,
    'markup' => Byrcsc\Mentions\Parsers\MarkupMentionParser::class,
],

default_parser must name an entry in parsers. Each class must implement MentionParser. The parser manager throws InvalidArgumentException when it resolves a missing name or invalid class.

A source model may override the default by returning a registered name from mentionParser().

Regex settings

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

The parser escapes trigger before adding it to the regular expression. A trigger may contain a character such as + without manual escaping.

The parser inserts handle_pattern as a regular-expression fragment. Do not include delimiters. Both values must be non-empty strings.

This pattern permits dots and hyphens:

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

Default column resolver

The short array form uses ColumnMentionResolver:

'resolvers' => [
    'users' => [
        'model' => App\Models\User::class,
        'column' => 'username',
    ],
],

The expanded form selects another resolver class while retaining the model and column metadata used for markup ID lookup:

'resolvers' => [
    'users' => [
        'resolver' => App\Mentions\TenantUserResolver::class,
        'model' => App\Models\User::class,
        'column' => 'username',
    ],
],

The container receives modelClass and column constructor arguments when it creates an array-defined resolver.

Self-contained resolver

Register a class directly when it needs no markup model mapping:

'resolvers' => [
    'tenant-users' => App\Mentions\TenantUserResolver::class,
],

The class must implement MentionResolver. Resolver keys must be strings. The manager ignores invalid entries while collecting definitions. It throws when it tries to create a resolver from an invalid array definition.

What to read next

  • Extend the package for complete parser and resolver examples.
  • Public API for the contract data structures.
  • Troubleshooting for configuration exceptions.
PreviousExtend the packageNextPublic API
View source

On this page

  1. Configuration keys
  2. Mention model and table
  3. Automatic synchronization
  4. Parser registration
  5. Regex settings
  6. Default column resolver
  7. Self-contained resolver
  8. What to read next