Usage with Filament
There are a couple of ways to use Commentions with Filament.
- Register the component in your Filament Infolists:
This works for Filament 3 and 4.
CommentsEntry::make('comments')
->mentionables(fn (Model $record) => User::all()),
If you wish to make the comments more distinct from the rest of the page, we recommend wrapping them in a Section.
For Filament 3:
\Filament\Infolists\Components\Section::make('Comments')
->schema([
CommentsEntry::make('comments')
->mentionables(fn (Model $record) => User::all()),
]),
For Filament 4:
\Filament\Schemas\Components\Section::make('Comments')
->components([
CommentsEntry::make('comments')
->mentionables(fn (Model $record) => User::all()),
]),
By default the entry uses the page's record. To comment on a different model (e.g. a pivot or a related record in a table modal), override it explicitly:
CommentsEntry::make('comments')
->record(fn () => $pivot)
->mentionables(User::all());
- Or in your table actions:
If you are using Filament 3, you must use CommentsTableAction in your table's actions array:
use Kirschbaum\Commentions\Filament\Actions\CommentsTableAction;
->actions([
CommentsTableAction::make()
->mentionables(User::all())
])
If you are using Filament 4, you should use CommentsAction in recordActions instead:
use Kirschbaum\Commentions\Filament\Actions\CommentsAction;
->recordActions([
CommentsAction::make()
->mentionables(User::all())
])
- Or as a header action:
This works for Filament 3 and 4.
use Kirschbaum\Commentions\Filament\Actions\CommentsAction;
protected function getHeaderActions(): array
{
return [
CommentsAction::make()
->mentionables(User::all()),
];
}
- Or directly in form schemas for Edit pages (Filament 4):
use Filament\Forms\Components\ViewField;
public static function configure(Schema $schema): Schema
{
return $schema
->components([
// Your other form fields...
ViewField::make('comments_section')
->view('...') // View file
->viewData(fn ($livewire) => [
'record' => $livewire->record ?? null
])
->columnSpanFull()
->hiddenLabel(),
]);
}
View file contents
Filament 3:
@livewire('commentions::comments', [
'record' => $record,
'mentionables' => \App\Models\User::all(),
'readonly' => $readonly ?? false
])
Filament 4:
@livewire('commentions.comments', [
'record' => $record,
'mentionables' => \App\Models\User::all(),
'readonly' => $readonly ?? false
])
To make the form comments readonly, pass the readonly flag in the viewData:
ViewField::make('comments_section')
->view('...') // View file
->viewData(fn ($livewire) => [
'record' => $livewire->record ?? null,
'readonly' => true, // Enable readonly mode
])
->columnSpanFull()
->hiddenLabel(),
Note: For View pages, continue using the infolist approach (option 1) as it works perfectly in that context.