›
byrcsc/laravel-mentions · 1.x
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.
| Key | Default | Purpose |
|---|---|---|
model | Package Mention class | Model used for every mention record |
table | mentions | Table used by the model and migration |
auto_sync | true | Runs sync after normal Eloquent saves |
default_parser | regex | Parser name used without a model override |
parsers | regex and markup mappings | Parser names mapped to class strings |
resolvers | Incomplete default definition | Ordered 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.
'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.
'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.
'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().
'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_.-]+',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.
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.