›
byrcsc/laravel-mentions · 1.x
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.
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;
}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.
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();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.