F
Filament14mo ago
Filip

Override the PHP file of database notifications drawer livewire component

I want to override the PHP file of this livewire component (database notifications drawer): https://user-images.githubusercontent.com/14108109/273273479-ca1a171a-1c0f-4485-9e2c-3982a3bb2d3d.png What I want is to edit the actions of the buttons on the drawer (Clear, Mark all as read...) The class in in vendor/Filament/Notifications/src/Livewire, it's called DatabaseNotifications.php
Solution:
i write a post about this case, u can see this post
Rupadana
Filamentphp 3 : Custom Database Notification Actions | Rupadana
Personal website, portfolio, blog, software engineer roadmap, programming tips of rupadana
Jump to solution
22 Replies
Filip
FilipOP14mo ago
Thanks @Vp but those pages do not answer my question
Filip
FilipOP14mo ago
That doesn't answer my answer neither
wyChoong
wyChoong14mo ago
Then maybe explain what you want better?
Rupadana
Rupadana14mo ago
U can create a new class, extend the DatabaseNotification and override the method
Filip
FilipOP14mo ago
Yeah sure, I want to edit the actions of the buttons: Mark all as read, clear and the X button of the notification, basically what I want is to overwrite the class vendor/Filament/Notifications/src/Livewire/DatabaseNotifications.php, which is the PHP file of the notification drawer livewire component. Reason: those buttons are are using mass assignment to change the notifications which means no events will be triggered but I want the events to be triggered. Yes I can do that, but how I will tell Filament to use my new class?
binaryfire
binaryfire14mo ago
If you're using the notifications package with a standalone page you can use a custom view instead of database-notifications that uses your extended class. But I'm not sure there's an easy way to do it with a panel... Another option is making a PR to add events to the methods in DatabaseNotifications
Solution
Rupadana
Rupadana14mo ago
i write a post about this case, u can see this post
Rupadana
Filamentphp 3 : Custom Database Notification Actions | Rupadana
Personal website, portfolio, blog, software engineer roadmap, programming tips of rupadana
binaryfire
binaryfire14mo ago
How are you removing the default database-notifications component from the panel? As far as I can tell it's hardcoded in all the views: https://github.com/filamentphp/filament/blob/062b13a724743b720ee488cdf380505f087e7fa4/packages/panels/resources/views/components/topbar/index.blade.php#L132 So by adding @livewire('database-custom-notifications'), aren't you just opening a second modal over the top of the default one?
Rupadana
Rupadana14mo ago
in my case, the database-notifications need manual registered which version included this?
Rupadana
Rupadana14mo ago
u can set databaseNotification to false in the panel provider
No description
Rupadana
Rupadana14mo ago
but, if many people need to override DatabaseNotification livewire, it better to add some method to custom it in panel provider
Rupadana
Rupadana14mo ago
adding this method to HasNotification trait
No description
Rupadana
Rupadana14mo ago
and then call it here
No description
Rupadana
Rupadana14mo ago
or simply like this
No description
Rupadana
Rupadana14mo ago
maybe we need to create a PR
Rupadana
Rupadana14mo ago
GitHub
Custom DatabaseNotifications Livewire by rupadana · Pull Request #8...
This PR add new parameter to databaseNotification in HasNotification trait and modify some topbar/index.blade.php Changes have been thoroughly tested to not break existing functionality. New fu...
Filip
FilipOP14mo ago
That should work, thanks so much, I will give it a try Great addition, thank you
Rupadana
Rupadana14mo ago
You're welcome
wyChoong
wyChoong14mo ago
reminder: the mass assignment is done for performance. in your implementation, you should use a queue
Filip
FilipOP14mo ago
thnks
Want results from more Discord servers?
Add your server