F
Filament7mo ago
nowak

How to add a link to resource entry in a database notification?

I have a Controller in my laravel app that gets triggered when a create record form is submitted from a Vue frontend, and I am wondering how to add an action to the notification that navigates to the created record. I tried this:
return DB::transaction(function () use ($input) {
$complaint = new UserOrderComplaint([
'user_order_id' => $input['user_order_id'],
'reason' => $input['reason'],
'status' => $input['status'],
]);

$complaint->save();

// Notify all users with the super_admin role
$superAdmins = User::role('super_admin')->get();

foreach ($superAdmins as $superAdmin) {
Notification::make()
->title('New User Order Complaint')
->body('A new complaint has been submitted.')
->actions([
Action::make('view')
->button()
->url(fn ($complaint): string => UserOrderComplaintResource::getUrl('edit', ['complaint' => $complaint->id])),
])
->sendToDatabase($superAdmin);
event(new DatabaseNotificationsSent($superAdmin));
}

return $complaint;
});
return DB::transaction(function () use ($input) {
$complaint = new UserOrderComplaint([
'user_order_id' => $input['user_order_id'],
'reason' => $input['reason'],
'status' => $input['status'],
]);

$complaint->save();

// Notify all users with the super_admin role
$superAdmins = User::role('super_admin')->get();

foreach ($superAdmins as $superAdmin) {
Notification::make()
->title('New User Order Complaint')
->body('A new complaint has been submitted.')
->actions([
Action::make('view')
->button()
->url(fn ($complaint): string => UserOrderComplaintResource::getUrl('edit', ['complaint' => $complaint->id])),
])
->sendToDatabase($superAdmin);
event(new DatabaseNotificationsSent($superAdmin));
}

return $complaint;
});
Where I get this error:
Error creating complaint: An attempt was made to evaluate a closure for [Filament\Notifications\Actions\Action], but [$complaint] was unresolvable.
Error creating complaint: An attempt was made to evaluate a closure for [Filament\Notifications\Actions\Action], but [$complaint] was unresolvable.
Any help is much appreciated!
2 Replies
Dan Harrin
Dan Harrin7mo ago
you just need to remove the $complaint arg from the url function, its already available as defined above
nowak
nowakOP7mo ago
Thank you! It works like this:
->url(UserOrderComplaintResource::getUrl('edit', ['record' => $complaint]))
->url(UserOrderComplaintResource::getUrl('edit', ['record' => $complaint]))
Want results from more Discord servers?
Add your server