Relation manger update change field on parent form?

Is it possible for a change/create of a child record in a relation manager to update a field on the parent form? I have a parent resource form that displays the number of active child table rows. If the user adds a new active child record I'd like the count field to change automatically. Is this possible? Thanks
Solution:
I found this trick https://v2.filamentphp.com/tricks/update-main-form-after-relationship-manager-crud which I thought was exactly what I needed but it doesn't seem to work (I had to change the listener code as it was using $this in the static form definition function) and pass the model as $record to the closure). Has anyone made this work?
Filament
Update Main form after Relationship Manager CRUD by iotron - Tricks...
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
Jump to solution
6 Replies
Patrick Boivin
You could probably emit a Livewire event from the relation manager to the page, when a new item gets added or updated.
rich06
rich06OP2y ago
Thanks - I can see that I can add a closure and $livewire->dispatchBrowserEvent('whatever') to the Create and Edit Actions for the child record form. However I can't see from the docs how to add an event listener to the parent form (I'm using the Admin package so I don't have access to the blade files). Any examples out there?
Patrick Boivin
Yeah dispatchBrowserEvent() is probably an option, but I was thinking about Livewire events. I'm thinking you could call $this->emit('refreshForm') when the Create or Edit action is done, and then have a Livewire listener on your Page component : https://laravel-livewire.com/docs/2.x/events#event-listeners
Livewire
Events | Livewire
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
rich06
rich06OP2y ago
Thanks again - you can probably tell I am new to Filament! So where do I find/access the Page components? I am using the Admin package i.e. I am working with a Resource class and as far as I can see there are no Livewire component classes published... TIA!
Solution
rich06
rich062y ago
I found this trick https://v2.filamentphp.com/tricks/update-main-form-after-relationship-manager-crud which I thought was exactly what I needed but it doesn't seem to work (I had to change the listener code as it was using $this in the static form definition function) and pass the model as $record to the closure). Has anyone made this work?
Filament
Update Main form after Relationship Manager CRUD by iotron - Tricks...
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
rich06
rich06OP2y ago
okay - I got it working now. After seeing the comment on that trick page it seems the protected $listeners = ['refresh' => '$refresh']; has to be added to the edit/create page resources not the maiin admin panel resource - thanks @pboivin for responding!

Did you find this page helpful?