F
Filamentβ€’6mo ago
momostafa

How to save Reverb Broadcasted notifications to database?

Hi, I am using Reverb Broadcast and below code sends and displays broadcasted notification properly on the frontend but it is not saved on default notification database for later viewing like when using notification database method. how to save notifications to database when using broadcast method?
$title = $data['title'];
$message = $data['message'];
$user = auth()->user();
$url = $data['url'];

$user->notify(
Notification::make()
->success()
->title($title)
->body($message)
->persistent()
->actions([
Action::make('View')
->button()
->url($url),
])
->toBroadcast(),
);
$title = $data['title'];
$message = $data['message'];
$user = auth()->user();
$url = $data['url'];

$user->notify(
Notification::make()
->success()
->title($title)
->body($message)
->persistent()
->actions([
Action::make('View')
->button()
->url($url),
])
->toBroadcast(),
);
Thanks for your help and support
2 Replies
gustavo.dev
gustavo.devβ€’6mo ago
Hi! You can use this method to save the record in the database.
->sendToDatabase
->sendToDatabase
Here is the link to the documentation. https://filamentphp.com/docs/3.x/notifications/database-notifications#sending-database-notifications
momostafa
momostafaOPβ€’6mo ago
Thanks a lot for your response, yes that worked perfectly thank you so much πŸ‘ after some trial and errors as the documentation doesn't clearly point out to it this is how I have implemented it
$title = $data['title'];
$message = $data['message'];
$url = $data['url'];
$user = User::find($data['user_id']);

Notification::make()
->success()
->title($title)
->body($message)
//->persistent()
->actions([
Action::make('View')
->button()
->url($url, shouldOpenInNewTab: true),
])
->broadcast($user)
//queue:listen or queue:work should be running so that the notification will be displayed under the notifications modal panel (Bell Icon)
->sendToDatabase($user)
->send();
// use instead of database polling
event(new DatabaseNotificationsSent($user));
$title = $data['title'];
$message = $data['message'];
$url = $data['url'];
$user = User::find($data['user_id']);

Notification::make()
->success()
->title($title)
->body($message)
//->persistent()
->actions([
Action::make('View')
->button()
->url($url, shouldOpenInNewTab: true),
])
->broadcast($user)
//queue:listen or queue:work should be running so that the notification will be displayed under the notifications modal panel (Bell Icon)
->sendToDatabase($user)
->send();
// use instead of database polling
event(new DatabaseNotificationsSent($user));
Want results from more Discord servers?
Add your server