›
byrcsc/laravel-mentions · 1.x
Read mention text from more than one attribute on the same source model.
If mentions can appear in more than one column, list every column on the source model. The package reads them together and stores each target once, even when the same handle appears in several columns.
Add each text column to $mentionableAttributes:
use Byrcsc\Mentions\Concerns\HasMentions;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use HasMentions;
/** @var list<string> */
protected array $mentionableAttributes = [
'summary',
'body',
'editor_notes',
];
}If @jane appears in both summary and body, the source still stores one
mention row for Jane.
Removing Jane from one attribute keeps the row while another configured attribute still mentions her.
Override mentionableAttributes() when the columns depend on model state:
/** @return list<string> */
protected function mentionableAttributes(): array
{
return $this->is_internal
? ['body', 'internal_notes']
: ['body'];
}The package calls the method during each synchronization. Return attribute names as strings.
HasMentions passes string values to the parser. A null, integer, array, cast
object, or other non-string value becomes an empty string for that sync.
If a cast returns a value object, expose the underlying text through a string
attribute or override mentionableAttributes() to select a stored string
column.
One synchronization selects one parser for all configured attributes. Do not mix plain text and HTML columns on the same source model unless a custom parser understands both formats.
Separate the formats into different source models, or write a custom parser that applies a defined rule to each input string.