Essentials
Mentions
User @mentions with autocomplete and notification support.
How Mentions Work
Type @ in the comment editor to trigger user autocomplete. Select a user to insert a mention. When the comment is saved, the MentionParser extracts mentions and:
- Syncs mention records in the
comment_mentionstable - Dispatches a
UserMentionedevent for each newly mentioned user - The
SendUserMentionedNotificationlistener sends notifications - If auto-subscribe is enabled, mentioned users are subscribed to the thread
Default Resolver
The DefaultMentionResolver searches the commenter model using the configured name_column (defaults to name):
// Searches: User::where('name', 'like', "{$query}%")
// Limited to: config('comments.mentions.max_results') results
Custom Name Column
If your users table uses a different column for names, set name_column in the config:
// config/comments.php
'mentions' => [
'name_column' => 'username', // or 'full_name', etc.
],
Multi-Column Search
If the display name is composed of multiple columns (e.g. firstname + lastname), configure search_columns:
// config/comments.php
'mentions' => [
'search_columns' => ['firstname', 'lastname'],
],
Then register a name resolver in your AppServiceProvider::boot():
use Relaticle\Comments\CommentsConfig;
CommentsConfig::resolveUserNameUsing(
fn ($user) => $user->firstname . ' ' . $user->lastname
);
Custom Mention Resolver
Implement the MentionResolver interface to customize user search behavior:
namespace App\Comments;
use Illuminate\Support\Collection;
use Relaticle\Comments\Contracts\MentionResolver;
class TeamMentionResolver implements MentionResolver
{
public function search(string $query): Collection
{
return User::query()
->where('team_id', auth()->user()->team_id)
->where('name', 'like', "{$query}%")
->limit(config('comments.mentions.max_results'))
->get();
}
public function resolveByNames(array $names): Collection
{
return User::query()
->where('team_id', auth()->user()->team_id)
->whereIn('name', $names)
->get();
}
}
Register it in your config:
// config/comments.php
'mentions' => [
'resolver' => App\Comments\TeamMentionResolver::class,
'max_results' => 5,
],
Configuration
| Key | Default | Description |
|---|---|---|
mentions.resolver | DefaultMentionResolver::class | User search implementation |
mentions.max_results | 5 | Maximum autocomplete results |
mentions.name_column | 'name' | DB column used for display and resolution |
mentions.search_columns | [name_column] | DB columns searched during autocomplete |