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

Mention groups.

Let source text mention teams, departments, or other group models alongside users.

A support note may mention a person with @jane or a whole team with @billing. Add another target lookup when handles can name a team, department, role, or other Eloquent model.

1. Make the group mentionable

Add Mentionable to the target model:

namespace App\Models;

use Byrcsc\Mentions\Concerns\Mentionable;
use Illuminate\Database\Eloquent\Model;

class Team extends Model
{
    use Mentionable;
}

2. Register the group resolver

Add the group after the user resolver:

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

@jane can now point to a User and @engineering can point to a Team.

Order matters when both tables contain the same value. The first resolver that finds a target claims the candidate.

3. Query a group target

Groups receive the same reverse relationship and source scope as users:

$team = Team::query()->where('slug', 'engineering')->firstOrFail();

$mentions = $team->mentionedIn()->with('source')->get();
$posts = Post::query()->whereMentions($team)->get();

Filter reverse records to one source class when several models can mention the team:

$taskMentions = $team->mentionedIn()
    ->fromSourceType(Task::class)
    ->with('source')
    ->get();

Decide what a group mention means

The package stores one row pointing to the Team model. It does not create rows for team members or dispatch one event per member.

Expand recipients in your notification listener. Read current membership when the listener handles the event. Snapshot recipients in application storage when your delivery rules require historical membership.

What to read next

  • Resolving targets for precedence between target classes.
  • Querying mentions for polymorphic source loading.
  • React to lifecycle events to notify group members.
PreviousUse markup mentionsNextQuerying mentions
View source

On this page

  1. 1. Make the group mentionable
  2. 2. Register the group resolver
  3. 3. Query a group target
  4. Decide what a group mention means
  5. What to read next