PHP code example of codenzia / filament-comments

1. Go to this page and download the library: Download codenzia/filament-comments 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/ */

    

codenzia / filament-comments example snippets


use Codenzia\FilamentComments\FilamentCommentsPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            FilamentCommentsPlugin::make(),
        ]);
}

// config/filament-comments.php
'tenancy' => [
    'enabled' => true,
    'tenant_column' => 'company_id', // the tenant foreign key on the comment tables
    'tenant_resolver' => null,        // null = use the current Filament panel tenant
],

'tenant_resolver' => \App\Tenancy\CurrentTenantResolver::class, // public function __invoke(): ?int

// or a closure (note: not config:cache-safe)
'tenant_resolver' => fn () => app(\App\Tenancy\CurrentTeam::class)->id(),

use Codenzia\FilamentComments\Traits\HasComments;

class Post extends Model
{
    use HasComments;
}

$post->comment('Great article!');
$post->commentAsUser($user, 'Thanks for sharing.');

use Codenzia\FilamentComments\Models\CommentChannel;

// 1-on-1 DM (legacy two-argument syntax still works)
$dm = CommentChannel::findOrCreateDirectMessage($userId1, $userId2);

// Group DM — pass an array of user IDs
$dm = CommentChannel::findOrCreateDirectMessage([$userId1, $userId2, $userId3]);

// config/filament-comments.php
'sidebar_limit' => [
    'channels' => 5,        // show 5 most recent channels
    'direct_messages' => 5,  // show 5 most recent DMs
],

// config/filament-comments.php
'navigation_groups' => [
    'channels' => 'Channels',
    'direct_messages' => 'Direct Messages',
],

'permissions' => [
    // Channels
    'create_channel' => 'create_comment_channel',
    'update_channel' => 'update_comment_channel',
    'delete_channel' => 'delete_comment_channel',
    'view_channel'   => 'view_comment_channel',

    // Direct Messages
    'view_direct_message'      => null, // null = any authenticated user
    'create_direct_message'    => null,
    'delete_direct_message'    => null,
    'add_member_direct_message' => null,
],

'permissions' => [
    'create_channel' => null, // any authenticated user can create channels
    'update_channel' => 'update_comment_channel',
    'delete_channel' => 'delete_comment_channel',
    'view_channel'   => null,
    'view_direct_message'      => null,
    'create_direct_message'    => null,
    'delete_direct_message'    => null,
    'add_member_direct_message' => null,
],

use Codenzia\FilamentComments\Commands\InstallCommand;

InstallCommand::seedPermissions();

// Example: grant channel management to a "moderator" role
$role = Role::findByName('moderator');
$role->givePermissionTo([
    'create_comment_channel',
    'update_comment_channel',
    'delete_comment_channel',
    'view_comment_channel',
]);

use Codenzia\FilamentComments\Filament\Pages\ManageChannelsPage;

if (ManageChannelsPage::can('create_channel')) {
    // user has the create_comment_channel permission
}

// config/filament-comments.php
'composer' => [
    // Poll, Checklist, Risk. Omitting the key entirely keeps all six.
    'types' => ['vote', 'todo', 'risk'],
],

// config/filament-comments.php
'auto_approve' => false,

// config/filament-comments.php
'moderation' => [
    // fn (?Model $user, ?Model $record): bool — true = publish now.
    'auto_approve_resolver' => fn ($user, $record) => ! $record?->holds($user),
],

namespace App\Comments;

class PublishesImmediately
{
    public function __invoke(?Model $user, ?Model $record): bool
    {
        return $user !== null && ! ReviewAccess::isModerated($user, $record);
    }
}

'moderation' => [
    'moderator_resolver' => App\Comments\IsReviewTeam::class,
],

Comment::query()->visibleTo(auth()->user(), $record)->get();

// config/filament-comments.php
'composer' => [
    'bg' => '#ffffff',          // light mode
    'dark_bg' => '#16181C',     // dark mode
    'show_settings' => false,   // show a settings cog with color picker
    'types' => [...],           // which types the + menu offers — see Comment Types
],

// config/filament-comments.php
'reactions' => [
    'like' => '👍',
    'love' => '❤️',
    'laugh' => '😄',
    'wow' => '😮',
    'sad' => '😢',
    'angry' => '😠',
],

// Programmatic usage
$comment->pin();
$comment->unpin();

// Query pinned comments
Comment::pinned()->get();

// Programmatic usage
$comment->resolve();        // resolves as current user
$comment->resolve($userId); // resolves as specific user
$comment->unresolve();

// Query scopes
Comment::resolved()->get();
Comment::unresolved()->get();

// config/filament-comments.php
'features' => [
    'priorities' => true, // false hides the control and refuses the write
],

'priorities' => [
    'vocabulary' => [
        'urgent' => ['label' => 'Urgent', 'color' => 'danger'],
        'later'  => ['label' => 'Later',  'color' => 'gray'],
    ],
],

use Codenzia\FilamentComments\Models\Comment;

Comment::byPriority('blocker')->get();              // one priority
Comment::byPriority(['blocker', 'must'])->get();    // several
Comment::orderByPriority()->get();                  // blocker first, null last
Comment::orderByPriority('desc')->get();            // fully reversed: null first

// Compose freely
$post->comments()->withTag('a11y')->byPriority('blocker')->orderByPriority()->get();

$comment->priority;         // 'blocker' | 'must' | 'nice' | null
$comment->hasPriority();    // bool
$comment->priorityLabel();  // 'Blocker' (translated), or null
$comment->priorityColor();  // 'danger', or 'gray' when unset

// config/filament-comments.php
'features' => [
    'tags' => true, // false hides the input and refuses the write
],

'tags' => [
    'max_per_comment' => 5,
    'max_length' => 32,
    'suggestion_limit' => 20,
    'suggestion_scope' => null,
],

'suggestion_scope' => fn ($query, $record) => $query
    ->where('commentable_type', $record->getMorphClass())
    ->where('commentable_id', $record->getKey()),

Comment::withTag('a11y')->get();                    // carries this tag
Comment::withAnyTag(['a11y', 'copy'])->get();       // carries at least one
Comment::withAnyTag('a11y')->get();                 // a single string also works

$comment->tags;       // ['a11y', 'copy'] — always a list, never null
$comment->hasTags();  // bool

$task->comment('The CTA is unreadable on mobile', null, true, [
    'priority' => 'blocker',
    'tags' => ['a11y', 'mobile'],
]);

// Or directly
$comment->update(['priority' => 'must', 'tags' => ['copy']]);

// Check if bookmarked
$comment->isBookmarkedBy();       // current user
$comment->isBookmarkedBy($userId); // specific user

// On any model using HasComments
$task->toggleWatch();         // toggle for current user
$task->isWatchedBy();         // check if current user is watching
$task->isWatchedBy($userId);  // check specific user
$task->commentWatchers();     // MorphMany relationship

// config/filament-comments.php
'task_mentionable' => [
    'model' => \App\Models\Task::class,
    'column' => ['id' => 'id', 'label' => 'title'],
    'url' => 'admin/tasks/{id}',
],

// Relationship on Comment model
$comment->linkedTask; // BelongsTo relationship

// config/filament-comments.php
'digest' => [
    'enabled' => false,
    'schedule' => 'daily',
    'time' => '09:00',
],

// bootstrap/app.php or app/Console/Kernel.php
$schedule->command('filament-comments:send-digest')->dailyAt('09:00');

// config/filament-comments.php
'code_highlighting' => true, // enabled by default

// config/filament-comments.php
'link_previews' => [
    'enabled' => true,
    'cache_ttl' => 3600, // cache previews for 1 hour
],

return [
    // Models
    'comment_class' => \Codenzia\FilamentComments\Models\Comment::class,
    'user_model' => null, // defaults to auth config
    'project_model' => \App\Models\Project::class,
    'event_model' => null, // optional: persist events to a model

    // Table names
    'table_name' => 'comments',
    'reactions_table_name' => 'comments_reactions',
    'channels_table_name' => 'comment_channels',
    'channel_members_table_name' => 'comment_channel_members',

    // Navigation groups
    'navigation_groups' => [
        'channels' => 'Channels',
        'direct_messages' => 'Direct Messages',
    ],

    // Behavior
    'auto_approve' => true, // set false to ,    'color' => 'warning'],
            'nice'    => ['label' => 'filament-comments::messages.priorities.nice',    'color' => 'gray'],
        ],
    ],

    // Tag caps + autocomplete scope. See "Tags" above.
    'tags' => [
        'max_per_comment' => 5,
        'max_length' => 32,
        'suggestion_limit' => 20,
        'suggestion_scope' => null, // null = same commentable_type
    ],

    // Editor
    'editor' => [
        'placeholder' => 'Type your comment here...',
        'height' => 100,
    ],

    // Composer appearance
    'composer' => [
        'bg' => '#ffffff',          // light mode background
        'dark_bg' => '#16181C',     // dark mode background
        'show_settings' => false,   // settings cog with color picker
    ],

    // Mentions
    'mentionable' => [
        'model' => \App\Models\User::class,
        'trigger' => '@',
        'column' => [
            'id' => 'id',
            'label' => 'name',
            'value' => 'name',
            'email' => 'email',
            'avatar' => 'profile_photo_path', // see "User avatars" below
        ],
        'avatar_disk' => 'public',
        'url' => 'admin/users/{id}',
    ],
];
bash
php artisan filament-comments:install
bash
php artisan migrate
css
/* resources/css/filament/{panel}/theme.css */
@source '../../../../vendor/codenzia/*/src/**/*.php';
@source '../../../../vendor/codenzia/*/resources/views/**/*.blade.php';
blade
{{-- Read-only chips. Renders nothing when the comment has neither. --}}
<x-filament-comments::triage-chips :comment="$comment" />

{{-- The composer row. Point the *-method props at your own Livewire methods. --}}
<x-filament-comments::triage-composer
    :priority="$this->priority"
    :tags="$this->tags"
    :options="$this->priorityOptions()"
    :suggestions="$this->tagSuggestions()"
    set-method="setPriority"
    add-method="addTag"
    remove-method="removeTag"
/>
bash
php artisan vendor:publish --tag="filament-comments-config"