How Add a widget to relationManager form

Is there a way to add a widget to the forms of a RelationManager? I have attached a widget to a resource form through the EditPage:
protected function getFooterWidgets(): array {
return [
\App\Filament\Widgets\Comments::class
];
}
protected function getFooterWidgets(): array {
return [
\App\Filament\Widgets\Comments::class
];
}
This works so I added this method to the RelationManager. no error and no widget. Looking in Filament RelationManager.php there is no mention of widgets like there is in Resource.php . So what to try next?
4 Replies
MaZZie
MaZZie3w ago
I use the PanelsRenderHook::RESOURCE_RELATION_MANAGER_BEFORE
trait RelationWidgets
{
public function boot(): void
{
$widget = str_replace('RelationManager', 'Widget', static::class);
FilamentView::registerRenderHook(
PanelsRenderHook::RESOURCE_RELATION_MANAGER_BEFORE,
fn (): string => \Blade::render('@livewire(\''.$widget.'\', ["resourceId" => $this->getOwnerRecord()->id])'),
);
}
}
trait RelationWidgets
{
public function boot(): void
{
$widget = str_replace('RelationManager', 'Widget', static::class);
FilamentView::registerRenderHook(
PanelsRenderHook::RESOURCE_RELATION_MANAGER_BEFORE,
fn (): string => \Blade::render('@livewire(\''.$widget.'\', ["resourceId" => $this->getOwnerRecord()->id])'),
);
}
}
The widget is living in app/Filament/Resources/{yourResource}/Widgets/ and has the name of your RelationManagerClass (if your RelationManager is HoursRelationManger than the widget should be HoursWidget)
ddoddsr
ddoddsrOP3w ago
Gotta try this! thanks I tried : made a Trait as above and added that trait to the Relation Manager.. When I click on edit in the relation manager I get a 'loading ' icon the first time after refresh, then it opens the modal without the widget.
MaZZie
MaZZie3w ago
Are you sure that you are in the boot() function? I had this when i had it in the mount().
ddoddsr
ddoddsrOP2w ago
Yes it was on boot() still have to click 1x before it will allow edit.

Did you find this page helpful?