›
byrcsc/laravel-mentions · 1.x
Inspect the database row that connects a mentioning model to its target.
Use a mention record when you need more than the model named in the text. The record gives you the mentioning model, the target model, the original handle, and the time the package created the link.
$mention = $comment->mentions()->with(['source', 'target'])->firstOrFail();
$mention->source;
$mention->target;
$mention->handle;The package calls the model containing the text the source. It calls the model named by the text the target.
Both sides use Eloquent polymorphic types:
| Column | Stored value |
|---|---|
source_type | Source morph class or morph-map alias |
source_id | Source key as a string |
target_type | Target morph class or morph-map alias |
target_id | Target key as a string |
handle | Parsed handle, or null for ID-based markup |
created_at | Time the source first mentioned the target |
updated_at | Time the mention row was created or later changed |
The ID columns support integer, UUID, and ULID model keys. Each morph type and ID column is 191 characters long.
A unique index covers source_type, source_id, target_type, and
target_id. Repeating @jane in one attribute, or across several scanned
attributes, still stores one row.
The synchronizer keeps the existing row when the source continues to mention
the same target. Its primary key and created_at value do not change.
The regex parser stores the handle used for the match:
$mention->handle; // "jane"The target columns remain the identity. Renaming Jane does not retarget or delete an existing row. The saved handle is a snapshot, not a live lookup.
The markup parser identifies targets by ID. Mention rows created from markup
store null in handle.
Deleting a source model through Eloquent prunes its mention rows. Soft deleting a source keeps them until the model is force deleted.
Deleting a target does not prune rows that point to it. The Mentionable trait
only defines a relationship. Add target cleanup in your application when it is
required by your retention rules.