Open custom modal from anywhere
I want to open a modal from a notification. But 'Filament\Notifications\Actions' doesn't seem to have this capability. So i'm thinking i should dispatch an event to open the modal, but since it's from a notification, the user may be in any part of the system. So where should i put the modal code/event-listener?
Solution:Jump to solution
Allright, RenderHooks are definitely the solution here.
I created a Livewire Component to handle the modal opening, and also a custom Action class (PdfListNotificationAction) to encapsulate all the mambo jambo required to set the custom modal content etc:
```
class ListPdfsModal extends Component implements HasForms, HasActions
{...
3 Replies
I think you can register the modal using render hooks
https://filamentphp.com/docs/3.x/support/render-hooks#registering-render-hooks
Something like this
Yeah, after a little more digging, i thought the same. I'm trying to get it done using RenderHooks, i'll post the code if its successful!
Solution
Allright, RenderHooks are definitely the solution here.
I created a Livewire Component to handle the modal opening, and also a custom Action class (PdfListNotificationAction) to encapsulate all the mambo jambo required to set the custom modal content etc:
In the custom component view, i add the filament-action-modal component:
I register the the RenderHook in my AppServiceProvider:
Inside the Job that fires the Database Notification, i just pass an Action that dispatches the event my custom Component listens to:
And voilá! Works like a charm!