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 by name:
// Searches: User::where('name', 'like', "{$query}%")
// Limited to: config('comments.mentions.max_results') results
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 |