PHP code example of asmit / filament-mention

1. Go to this page and download the library: Download asmit/filament-mention library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

asmit / filament-mention example snippets


    [
        'note' => [
            'state' => 'your comment message'
            'mentioned_YOUR-PLUCK-KEY' => [
                0 => 1,
                1 => 2,
                2 => 3,
            ]
    ]

return [
    'mentionable' => [
        'model' => \App\Models\User::class, // The model to use for mentions
        'column' => [
            'id' => 'id', // Unique identifier for the user
            'display_name' => 'name', // Display name for the mention
            'username' => 'username', // Username for the mention
            'avatar' => 'profile', // Avatar field (e.g. profile picture URL)
        ],
        'url' => 'admin/users/{id}', // this will be used to generate the url for the mention item
        'lookup_key' => 'username', // Used for static search (key in the dataset)
        'search_column' => 'username', // this will be used on dynamic search 
    'default' => [
        'trigger_with' => ['@', '#', '%'], // Characters to trigger mentions
        'trigger_configs' => [
            '@' => [
                'prefix' => '',
                'suffix' => '',
                'title_field' => 'name',
                'hint_field' => null,
            ],
            '#' => [
                'prefix' => '',
                'suffix' => '',
                'title_field' => 'name',
                'hint_field' => null,
            ],
            '%' => [
                'prefix' => '%',
                'suffix' => '%',
                'title_field' => 'title',
                'hint_field' => null,
            ],
        ],
        'menu_show_min_length' => 0, // Minimum characters to type before showing suggestions
        'menu_item_limit' => 10, // Maximum number of suggestions to display
        'prefix' => '', // Default prefix for all mentions
        'suffix' => '', // Default suffix for all mentions
        'title_field' => 'title', // Default field to use for title display
        'hint_field' => null, // Default field to use for hint display
    ],
];

use Asmit\Mention\Forms\Components\RichMentionEditor;

RichMentionEditor::make('bio')
    ->columnSpanFull(),

use Asmit\FilamentMention\Forms\Components\RichMentionEditor;
use Asmit\FilamentMention\Dtos\MentionItem;

RichMentionEditor::make('comments')
    ->key(fn () => rand())
    ->disableGrammarly()
    ->lookupKey('username')
    ->mentionableItems(function () {
        return User::all()->map(function ($user) {
            return (new MentionItem(
                id: $user->id,
                username: $user->username,
                displayName: $user->name,
                avatar: $user->profile,
                url: '/users/admin'.$user->id,
            ));
        })->toArray();
    }),

use \Asmit\FilamentMention\Concerns\HasMentionableForm

class FilamentPage {
    use HasMentionableForm;
    // ...
}

use Asmit\FilamentMention\Forms\Components\RichMentionEditor;
use Asmit\FilamentMention\Dtos\MentionItem;

RichMentionEditor::make('comments')
    ->key(fn () => rand())
    ->lookupKey('username')
    ->disableGrammarly()
    ->placeholder('Write your comment here...')
    ->getMentionableItemsUsing(function ($query) {
        return User::search($query)
            ->get()
            ->map(function ($user) {
                return new MentionItem(
                    id: $user->id,
                    username: $user->username,
                    displayName: $user->name,
                    avatar: $user->profile,
                    url: '#');
            })->toArray();
    })


use \Asmit\FilamentMention\Forms\Components\RichMentionEditor;

RichMentionEditor::make('note')
    ->pluck('id')
    ->getMentionableItemsUsing(function ($query) {
        return User::search($query)
                ->get()
                ->map(function ($user) {
                    return new MentionItem(
                        id: $user->id,
                        username: $user->username,
                        displayName: $user->name,
                        avatar: $user->profile,
                        url: '#');
                })->toArray();
        })

    [
        'note' => [
            'state' => 'your comment message'
            'mentioned_id' => [
                0 => 1,
                1 => 2,
                2 => 3,
            ]
    ]

RichMentionEditor::make('content')
    ->triggerWith(['@', '#', '%'])

RichMentionEditor::make('content')
    ->triggerWith(['@', '#', '%'])
    ->triggerConfigs([
        '@' => [
            'lookupKey' => 'username',
            'prefix' => '',
            'suffix' => '',
            'title_field' => 'name',
            'hint_field' => 'email',
        ],
        '#' => [
            'lookupKey' => 'tag',
            'prefix' => '#',
            'suffix' => '',
            'title_field' => 'name',
            'hint_field' => null,
        ],
        '%' => [
            'lookupKey' => 'name',
            'prefix' => '%',
            'suffix' => '%',
            'title_field' => 'title',
            'hint_field' => null,
        ],
    ])

RichMentionEditor::make('content')
    ->menuShowMinLength(0) // Show all items immediately

RichMentionEditor::make('content')
    ->prefix('%')
    ->suffix('%')

RichMentionEditor::make('content')
    ->triggerWith(['@', '%'])
    ->triggerConfigs([
        '@' => [
            'prefix' => '',
            'suffix' => '',
        ],
        '%' => [
            'prefix' => '%',
            'suffix' => '%',
        ],
    ])

RichMentionEditor::make('content')
    ->titleField('name')
    ->hintField('email')

RichMentionEditor::make('content')
    ->triggerWith(['@', '%'])
    ->triggerConfigs([
        '@' => [
            'title_field' => 'name',
            'hint_field' => 'email',
        ],
        '%' => [
            'title_field' => 'title',
            'hint_field' => null,
        ],
    ])

RichMentionEditor::make('content')
    ->triggerWith('%')
    ->prefix('%')
    ->suffix('%')
    ->menuShowMinLength(0)
    ->mentionsItems([
        [
            'id' => 1,
            'title' => 'SALUTATION',
            'value' => 'salutation',
        ],
        [
            'id' => 2,
            'title' => 'FIRST_NAME',
            'value' => 'firstName',
        ],
        // More variables...
    ])
bash
   php artisan filament:assets
   
bash
   php artisan vendor:publish --provider="Asmit\FilamentMention\FilamentMentionServiceProvider" --tag="asmit-filament-mention-config"