Deliver notifications in email
Hello,
I am wondering if there is any way to extend the Filament Notification class to be able to send notifications in email in a way that is similar to
->toBroadcast($user)
that is like ->toEmail($user)
. It doesn't need to be the most perfect email but my code is mostly based around Filament notifications so something simple to implement across the whole app is required.12 Replies
Look at implementation of
toBroadcast()
or toDatabase()
. It's quite simple. You could extend Filament\Notification
and add toMail()
, then add a generic MailNotification
that takes that data and sends mails.Do I just create a new class than extends Filament\Notification?
or does it need to be a plugin?
No need to be a plugin. Just a normal class using PHP. And instead of using the Filament class use your new class then
Thank you so much! Is it okay if I keep this discussion open while I try to implement it for any issues that may arise or should I reopen if any help is required?
Keep it open and come back if you need further assistance.
Hey, is there any way to accomplish this without having to change the namespaces? (Adding the modifier to the original Filament class) Not sure if that is possible in terms of how php itself works, obviously
Laravel has a Macro feature that is used by the Notification class. So you can define your own method. Check this article:
https://levelup.gitconnected.com/understanding-laravel-macros-e2f493484a38
Medium
Understanding Laravel Macros
Laravel macros allow us to add custom functionality to Laravel core components or classes. In other words, they allow us to extend Laravel…
Thank you so much!
Solution
This is how I solved it for future reference for anybody who needs it. I'm not sure if it is the cleanest way of doing things but I would however believe such a simple addition to the upstream could be helpful in many cases. Is there any reason it is neglected?
Thanks for sharing.
Is there any reason it is neglected?I just think it's not that common. Filament Notifications are mostly meant to be inside Filament
Thank you for the awesome project and the help. Take care!