FilamentF
Filament12mo ago
ddoddsr

Add laravel-comments to a RelationManager.

I followed the talk that Dan Harrin and Freek had about two years ago about Spaties laravel-comments in Filament v2. Also saw the v2 trick for this.
I made changes to the examples to make it work on FilamentV3 and I made some real progress, showing thc comments connected to a Resourcewith a widget. There is also a CommentsResource which I have add will upon request.
However, now I need the Comments on a RelationManager and don't see how to get the Widget working on a RelationManager.
Given the simplicity of the Widget what can I do with a page or livewire component?

This is a paid plugin so no channel?
install laravel-client and the livewire plugin
In App\Providers\AppServiceProvider. boot method
Filament::registerRenderHook(
    PanelsRenderHook::STYLES_AFTER,
    fn (): string => Blade::render('@laravelCommentsLivewireStyles'),
);

Filament::registerRenderHook(
    PanelsRenderHook::SCRIPTS_AFTER,
    fn (): string => Blade::render('@laravelCommentsLivewireScripts'),
);

Then in the model
use Spatie\Comments\Models\Concerns\HasComments;


use HasComments;
...
public function commentableName(): string
{
    return $this->first_name .' ' .$this->last_name  ;
}
public function commentUrl(): string
{
    return '';
}

Widget
<?php

namespace App\Filament\Widgets;

use Filament\Widgets\Widget;
use Illuminate\Database\Eloquent\Model;

class Comments extends Widget
{
    protected static string $view = 'filament.widgets.comments';

    public Model $record;

    public function getColumnSpan(): int | string | array
    {
        return $this->columnSpan;
    }


}

widgit view
<x-filament-widgets::widget>
    @if($record)
        <x-filament::section>
            <livewire:comments :model="$record" />
        </x-filament::section>
    @endif
</x-filament-widgets::widget>

All of the above works in a resource when I add the widget to getWidgets()

This does not work in the RelationManager getFooterWidgets()
Or getWidgets()
Was this page helpful?