happytodev/filament-comments
Filament plugin that adds comment functionality to your admin panel, with current support focused on OrbitPHP. Includes an install command and publishable config to get started quickly, plus tests and changelog for ongoing maintenance.
Installation
composer require happytodev/filament-comments
Publish the package assets and config:
php artisan vendor:publish --provider="Happytodev\FilamentComments\FilamentCommentsServiceProvider" --tag="filament-comments-config"
php artisan vendor:publish --provider="Happytodev\FilamentComments\FilamentCommentsServiceProvider" --tag="filament-comments-migrations"
Run migrations:
php artisan migrate
Register the Plugin
Add to app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\Happytodev\FilamentComments\FilamentCommentsPlugin::make(),
]);
}
First Use Case: Enable Comments on a Resource
Add the HasComments trait to your resource model:
use Happytodev\FilamentComments\Concerns\HasComments;
class Post extends Model
{
use HasComments;
}
Then, in your Filament resource class, add the HasCommentsTable trait:
use Happytodev\FilamentComments\Concerns\HasCommentsTable;
class PostResource extends Resource
{
use HasCommentsTable;
}
Commenting on Records
Nested Comments
threaded option in the config:
'threaded' => true,
reply() method in your resource actions:
public static function getCommentActions(Comment $comment): array
{
return [
Tables\Actions\Action::make('reply')
->label('Reply')
->action(function (Comment $comment) {
// Handle reply logic
}),
];
}
Customizing Comment Fields
php artisan vendor:publish --tag="filament-comments-views"
createCommentForm method in your resource:
public function createCommentForm(): array
{
return [
Forms\Components\Textarea::make('body')
->required()
->maxLength(1000),
Forms\Components\Select::make('status')
->options(['draft', 'published'])
->default('draft'),
];
}
Moderation and Approval
status field to implement approval workflows:
public function table(Table $table): Table
{
return $table
->columns([
// ...
Tables\Columns\SelectColumn::make('status')
->options(['draft' => 'Draft', 'published' => 'Published']),
]);
}
public static function getCommentBulkActions(): array
{
return [
Tables\Actions\BulkAction::make('publish')
->action(function (Collection $records) {
$records->update(['status' => 'published']);
}),
];
}
Notifying Users
CommentCreated) to trigger notifications:
public function boot()
{
Comment::created(function ($comment) {
Notification::route('mail', $comment->commentable->user->email)
->notify(new NewCommentNotification($comment));
});
}
EditAction, DeleteAction) for comments:
How can I help you explore Laravel packages today?