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

Installation and setup.

Install the package, publish its assets, and configure a target model.

Before a saved model can create mentions, the package needs somewhere to store them and a way to find each target. This guide creates the mentions table and maps handles such as @jane to your User model.

1. Install the package

Install the package with Composer:

composer require byrcsc/laravel-mentions

Laravel discovers Byrcsc\Mentions\MentionsServiceProvider through the package manifest. You do not need to register it manually.

2. Publish the migration

Publish the package migration and create the mentions table:

php artisan vendor:publish --tag="mentions-migrations"
php artisan migrate

Laravel adds the current timestamp to the generated filename. The migration creates indexes for both morph sides and a unique index across the source and target identity.

3. Publish the configuration

Publish config/mentions.php:

php artisan vendor:publish --tag="mentions-config"

The shipped resolver has no target model. Set one before saving source text that contains handles:

// config/mentions.php
'resolvers' => [
    'users' => [
        'model' => App\Models\User::class,
        'column' => 'name',
    ],
],

The default column resolver compares @jane with User::$name without case sensitivity. This works with Laravel's default User model. In production, a unique username column avoids ambiguity between equal display names.

4. Make the target queryable

Add Mentionable to the target model:

namespace App\Models;

use Byrcsc\Mentions\Concerns\Mentionable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Mentionable;
}

This trait adds mentionedIn(). Resolution itself only needs the model class in configuration, but reverse queries need the trait.

Configuration caching

Rebuild Laravel's configuration cache after changing resolver definitions in a deployed application:

php artisan config:cache

Long-running workers must restart before they use the new configuration.

What to read next

  • Quick start to add mention text to a source model.
  • Configuration for every key and default.
  • Published assets for the migration schema and publish tags.
PreviousIntroductionNextQuick start
View source

On this page

  1. 1. Install the package
  2. 2. Publish the migration
  3. 3. Publish the configuration
  4. 4. Make the target queryable
  5. Configuration caching
  6. What to read next