F
Filamentβ€’16mo ago
dansing

Database Notification Actions are Not Saved on Database

Actions are not showing
$job = $event->job;

Notification::make()
->info()
->title('Test')
->body("Test")
->sendToDatabase($job->account->user)
->actions([
ActionsAction::make('view')
->url(fn () => JobResource::getUrl('view', [$job])),
ActionsAction::make('markAsRead')
->markAsRead()
])
;
$job = $event->job;

Notification::make()
->info()
->title('Test')
->body("Test")
->sendToDatabase($job->account->user)
->actions([
ActionsAction::make('view')
->url(fn () => JobResource::getUrl('view', [$job])),
ActionsAction::make('markAsRead')
->markAsRead()
])
;
12 Replies
toeknee
toekneeβ€’16mo ago
Are they in the database? Are they showing in filament
dansing
dansingOPβ€’16mo ago
Yes the notifications are showing Except for the actions that I'm trying to add
toeknee
toekneeβ€’16mo ago
And when you check the datbase are they there? I would suspect you are not sending to the correct user
dansing
dansingOPβ€’16mo ago
No description
dansing
dansingOPβ€’16mo ago
Ohh, the actions are not being saved to database
{"actions":[],"body":"Test","color":null,"duration":"persistent","icon":"heroicon-o-information-circle","iconColor":"info","title":"Test","view":"filament-notifications::notification","viewData":[],"format":"filament"}
{"actions":[],"body":"Test","color":null,"duration":"persistent","icon":"heroicon-o-information-circle","iconColor":"info","title":"Test","view":"filament-notifications::notification","viewData":[],"format":"filament"}
toeknee
toekneeβ€’16mo ago
So ther eis your problem
dansing
dansingOPβ€’16mo ago
ya not sure why it doesn't save the actions to database
toeknee
toekneeβ€’16mo ago
is $job->account->user a correct user model? not a user_id ?
dansing
dansingOPβ€’16mo ago
$job->account->user is a user model
toeknee
toekneeβ€’16mo ago
You need to debug it
Majid Al Zariey
Majid Al Zarieyβ€’9mo ago
This problem is very frustrating. The solution is simple: use sendToDatabase after actions are initialized.
Notification::make()
->info()
->title('Test')
->body("Test")
->actions([
ActionsAction::make('view')
->url(fn () => JobResource::getUrl('view', [$job])),
ActionsAction::make('markAsRead')
->markAsRead()
])
->sendToDatabase($job->account->user);
Notification::make()
->info()
->title('Test')
->body("Test")
->actions([
ActionsAction::make('view')
->url(fn () => JobResource::getUrl('view', [$job])),
ActionsAction::make('markAsRead')
->markAsRead()
])
->sendToDatabase($job->account->user);
When you use sendToDatabase immediately after actions, it sends the notification to the database right away. This bypasses the actions because they haven't been initialized yet. This needs to be documented.
toeknee
toekneeβ€’9mo ago
Please feel free to make a documentation PR πŸ™‚

Did you find this page helpful?