›
byrcsc/laravel-mentions · 1.x
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.
Install the package with Composer:
composer require byrcsc/laravel-mentionsLaravel discovers Byrcsc\Mentions\MentionsServiceProvider through the
package manifest. You do not need to register it manually.
Publish the package migration and create the mentions table:
php artisan vendor:publish --tag="mentions-migrations"
php artisan migrateLaravel 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.
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.
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.
Rebuild Laravel's configuration cache after changing resolver definitions in a deployed application:
php artisan config:cacheLong-running workers must restart before they use the new configuration.