database notification

Can help me about databse notification please. I have a notifications table and add @livewire('database-notifications') to app.blade.php but it doesn't work
28 Replies
josef
josef16mo ago
doesnt work means what exactly?
shissaaa
shissaaaOP16mo ago
my code like this and it doesn't save data to database
No description
krekas
krekas16mo ago
what error message you get then?
shissaaa
shissaaaOP16mo ago
it doesn't have any error when I use send(), it's work normally but sendToDatabase doesn't work
krekas
krekas16mo ago
does it even hit aftercreate() method?
josef
josef16mo ago
have you enabled databaseNotifications in the provider?
shissaaa
shissaaaOP16mo ago
yes i have do it
No description
krekas
krekas16mo ago
so after creating record does it hit your method?
shissaaa
shissaaaOP16mo ago
yes, i test send() then it run nomarlly but sendToDatabase doesn't work I dont know I must config anything else
krekas
krekas16mo ago
check the docs maybe you missed something
SoraKeyheart
SoraKeyheart16mo ago
->sendToDatabse in version 3 is changed to ->toDatabase() here is my real code as an example:
// Web notification
$recipientsForNotification = User::where('accident_notification_enabled', true)->get();

foreach ($recipientsForNotification as $recipient) {
$recipient->notify(
Notification::make()
->title('New Accident Created')
->icon('heroicon-o-document-text')
->body(
"**New Accident: " .
__($record->ac_number->prefix ?? 'MVA#' . str_pad($record->ac_number, 4, '0', STR_PAD_LEFT)) .
" at location {$record->locationRelationship->name} was created by " . auth()->user()->name
)
->actions([
Action::make('View')
->url(AccidentResource::getUrl('view', ['record' => $record])),
])
->toDatabase(),
);
}
// Web notification
$recipientsForNotification = User::where('accident_notification_enabled', true)->get();

foreach ($recipientsForNotification as $recipient) {
$recipient->notify(
Notification::make()
->title('New Accident Created')
->icon('heroicon-o-document-text')
->body(
"**New Accident: " .
__($record->ac_number->prefix ?? 'MVA#' . str_pad($record->ac_number, 4, '0', STR_PAD_LEFT)) .
" at location {$record->locationRelationship->name} was created by " . auth()->user()->name
)
->actions([
Action::make('View')
->url(AccidentResource::getUrl('view', ['record' => $record])),
])
->toDatabase(),
);
}
krekas
krekas16mo ago
you are sending it in different way than he is
shissaaa
shissaaaOP16mo ago
yes I have test that way but it doesn't work too
SoraKeyheart
SoraKeyheart16mo ago
Just to Review: - did you do composer require filament/notifications:"^3.0-stable" -W? - and php artisan filament:install --scaffold --notifications - and php artisan filament:install --notifications ?
Dennis Koch
Dennis Koch16mo ago
There aren't any errors?
shissaaa
shissaaaOP16mo ago
yes i do everything no dont have error, it just doesn't save it in database
Dennis Koch
Dennis Koch16mo ago
The notifications table exists?
shissaaa
shissaaaOP16mo ago
of course
No description
Dennis Koch
Dennis Koch16mo ago
nd add @livewire('database-notifications') to app.blade.php but it doesn't work
From your screenshots it looks like you are using the panel, so no need to to this
shissaaa
shissaaaOP16mo ago
yes I do all the doc say 😢
Dennis Koch
Dennis Koch16mo ago
Did you publish Filament view files?
shissaaa
shissaaaOP16mo ago
How to publish this
josef
josef16mo ago
If you haven't, don't
shissaaa
shissaaaOP16mo ago
Thank you so much
anas660
anas66015mo ago
i have impelemnt notification which is showing in resource pages but not in custom pages see the image below
No description
Null Keso
Null Keso15mo ago
@shissaaa I've encountered this issue and I have to create a Laravel notification class then I changed the via from mail to database and add or replace the toMail to toDatabase method and return a Filament Notification For some unknown reason (either the issue is from the framework or in my setup) the code provided in the Notification docs doesn't work
Want results from more Discord servers?
Add your server