Clear Notification after Button Clicked

Is it possible to clear a specific database notification by clicking an action button?
Solution:
'x-on:click' => 'close' will delete the notification I guess. Try it
Jump to solution
16 Replies
toeknee
toeknee4mo ago
You can technically just delete the notification directly so no need to clear?
tinkypinky
tinkypinky4mo ago
How to access current notification within the Action?
toeknee
toeknee4mo ago
So you want to add a button to the popup notification to clear it?
tinkypinky
tinkypinky4mo ago
Yes Not Popup but Database Notification
toeknee
toeknee4mo ago
But database notifications have an X to them to remove it?
LeandroFerreira
LeandroFerreira4mo ago
this?
Notification::make()
->title('Saved successfully')
->success()
->actions([
\Filament\Notifications\Actions\Action::make('clear')
->label('Clear')
->extraAttributes([
'x-on:click' => 'close',
]),
])
Notification::make()
->title('Saved successfully')
->success()
->actions([
\Filament\Notifications\Actions\Action::make('clear')
->label('Clear')
->extraAttributes([
'x-on:click' => 'close',
]),
])
tinkypinky
tinkypinky4mo ago
This will close the modal. I want to delete it from the db.
LeandroFerreira
LeandroFerreira4mo ago
Where are you trying to do it?
tinkypinky
tinkypinky4mo ago
From the Notification Modal
LeandroFerreira
LeandroFerreira4mo ago
Do you have the notification id?
tinkypinky
tinkypinky4mo ago
Let me show you a little bit of code.
LeandroFerreira
LeandroFerreira4mo ago
I guess you can use in the action ->dispatch('notificationClosed', ['id' => 'notificationid'])
tinkypinky
tinkypinky4mo ago
If I click on clear, it deletes all notifications for the user. I want to delete only a specific notification after Download button is clicked
No description
Solution
LeandroFerreira
LeandroFerreira4mo ago
'x-on:click' => 'close' will delete the notification I guess. Try it
tinkypinky
tinkypinky4mo ago
Perfect. How did you came to know about this? I mean where to look in docs etc.
LeandroFerreira
LeandroFerreira4mo ago
The Filament docs are awesome, but sometimes we gotta dive into the source code to get things done.