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
josef2y ago
doesnt work means what exactly?
shissaaa
shissaaaOP2y ago
my code like this and it doesn't save data to database
No description
krekas
krekas2y ago
what error message you get then?
shissaaa
shissaaaOP2y ago
it doesn't have any error when I use send(), it's work normally but sendToDatabase doesn't work
krekas
krekas2y ago
does it even hit aftercreate() method?
josef
josef2y ago
have you enabled databaseNotifications in the provider?
shissaaa
shissaaaOP2y ago
yes i have do it
No description
krekas
krekas2y ago
so after creating record does it hit your method?
shissaaa
shissaaaOP2y ago
yes, i test send() then it run nomarlly but sendToDatabase doesn't work I dont know I must config anything else
krekas
krekas2y ago
check the docs maybe you missed something
SoraKeyheart
SoraKeyheart2y 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
krekas2y ago
you are sending it in different way than he is
shissaaa
shissaaaOP2y ago
yes I have test that way but it doesn't work too
SoraKeyheart
SoraKeyheart2y 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 Koch2y ago
There aren't any errors?
shissaaa
shissaaaOP2y ago
yes i do everything no dont have error, it just doesn't save it in database
Dennis Koch
Dennis Koch2y ago
The notifications table exists?
shissaaa
shissaaaOP2y ago
of course
No description
Dennis Koch
Dennis Koch2y 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
shissaaaOP2y ago
yes I do all the doc say 😢
Dennis Koch
Dennis Koch2y ago
Did you publish Filament view files?
shissaaa
shissaaaOP2y ago
How to publish this
josef
josef2y ago
If you haven't, don't
shissaaa
shissaaaOP2y ago
Thank you so much
anas660
anas6602y ago
i have impelemnt notification which is showing in resource pages but not in custom pages see the image below
No description
ඞ
2y 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

Did you find this page helpful?