Custom notifications service provider clarification

Hi everyone, I've created a custom notification view and I'm trying to send a custom notification in a CreateResource inside the create() function. I'm confused about where to include Notification::configureUsing(). It's mentioned in the documentation that it should be included in a service provider but I'm not sure where exactly since I want to only show it in a specific CreateResource page. Any clarification would be greatly appreciated.
4 Replies
Dennis Koch
Dennis Koch2y ago
You don’t need that one if you don’t want global configuration. Just set the view on the notification itself.
spinther
spintherOP2y ago
Thanks for the reply @Dennis Koch. Unfortunately, it's not working for some reason. The following code overrides the default view ands works fine when added to a service provider.
Notification::configureUsing(function (Notification $notification): void {
$notification->view("filament.notifications.api-key");
});
Notification::configureUsing(function (Notification $notification): void {
$notification->view("filament.notifications.api-key");
});
But using the following has no effect at all, and the notification renders the default view.
Notification::make()
->view("filament.notifications.api-key")
->title("$plainTextToken")
->body("Please make sure to copy your API key and save it in a secure location, as you will not have access to it again. This is crucial to ensure the safety and proper functioning of your account.")
->persistent()
->success()
->icon('heroicon-o-key')
->iconColor("success")
->send();
Notification::make()
->view("filament.notifications.api-key")
->title("$plainTextToken")
->body("Please make sure to copy your API key and save it in a secure location, as you will not have access to it again. This is crucial to ensure the safety and proper functioning of your account.")
->persistent()
->success()
->icon('heroicon-o-key')
->iconColor("success")
->send();
Am I doing something wrong?
filament/filament v2.17.28
filament/notifications v2.17.28
filament/filament v2.17.28
filament/notifications v2.17.28
Dennis Koch
Dennis Koch2y ago
Hm. I guess the issue is, that the view isn’t stored in the notification. So on the next page load when the notification is rendered to information is lost
spinther
spintherOP2y ago
Notification inherits from ViewComponent which has a $view property. I've tried to create a class that inherits from Notification and override $view but again, the notification renders the default view. I'll move on to something else now but in case anyone knows a way to render a custom view in a specific notification, please let me know. Thanks @Dennis Koch.
Want results from more Discord servers?
Add your server