Web push notifications

My client asked about adding web push notifications in the admin panel (so only on a specific subdomain and for logged in users). But after doing some research I haven't found much help on this in FilamentPHP. I've implemented database notifications in Filament and they work. Now I want to add a web push notification when a database notification is added. I tried doing this adding a livewire component in the renderHook then listening to wire events but with no luck. If someone knows a bit more about livewire and using events inside of Filament that would be great. Is the only option to use something like Echo or Pusher and I have to run another process on the server?
4 Replies
Benjamin
Benjamin3w ago
Same question here. I'm wondering if there it could be possible to use a Notification class (https://laravel.com/docs/11.x/notifications) and then a toFilament() method that return a Filament Notification (https://filamentphp.com/docs/3.x/notifications/database-notifications#sending-database-notifications). Did you find a way to do this @Fatboii ?
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Benjamin
Benjamin3w ago
Maybe this exemple @Fatboii :
use App\Models\User;
use Filament\Notifications\Notification;

public function toDatabase(User $notifiable): array
{
return Notification::make()
->title('Saved successfully')
->getDatabaseMessage();
}
use App\Models\User;
use Filament\Notifications\Notification;

public function toDatabase(User $notifiable): array
{
return Notification::make()
->title('Saved successfully')
->getDatabaseMessage();
}
Fatboii
FatboiiOP3w ago
Yo @Benjamin I did find a solution although web push notifications was more complex than i thought There is this Laravel library that I used to enabled sending push notifications from the notification API, you can use toDatabase and toWebPush at the same time and it will do both notifications https://github.com/laravel-notification-channels/webpush?tab=readme-ov-file When you have that setup you need a way for frontend to "listen" and "update" this. For this i created a Filament render hook and added a Livewire script (blade file) with some javascript https://gist.github.com/4RV1D/0f35ec69a68967dfdb88008b02aa1f43 Don't trust the script too much my JS knowledge isn't the best Then you also need a WebPushController in Laravel that can "save" and "delete" from that frontend script If you have any improvments or questions you can just @ me again
Benjamin
Benjamin3w ago
Thanks a lot for your feedback ! I'm gonna implement it in a few weeks (or months, Idk yet), I'll tell you at that time how I managed to do or 🙂 @Fatboii

Did you find this page helpful?