F
Filament2mo ago
nowak

Duplicate notifications from table action on page load

I have a UserOrderResource, where I have added a table action that navigates to the GroupOrderResource record for each UserOrder record:
Tables\Actions\Action::make('group_order')
->url(function (UserOrder $record): ?string {
// Use the already eager-loaded groupOrder if it's available
$groupOrder = $record->groupOrder()->withTrashed()->first();

// Check if the groupOrder exists and is not trashed
if (!$groupOrder || $groupOrder->trashed()) {

// Show a notification to the user
Notification::make()
->warning()
->title('Group Order Not Available')
->body("The group order for the user order by {$record->detail->full_name} with deadline: {$record->deadline} and id: {$record->id} is no longer available.")
->persistent()
->send();

return null; // Halt the action by not returning a URL
}
return GroupOrderResource::getUrl('edit', ['record' => $groupOrder]);
}),
Tables\Actions\Action::make('group_order')
->url(function (UserOrder $record): ?string {
// Use the already eager-loaded groupOrder if it's available
$groupOrder = $record->groupOrder()->withTrashed()->first();

// Check if the groupOrder exists and is not trashed
if (!$groupOrder || $groupOrder->trashed()) {

// Show a notification to the user
Notification::make()
->warning()
->title('Group Order Not Available')
->body("The group order for the user order by {$record->detail->full_name} with deadline: {$record->deadline} and id: {$record->id} is no longer available.")
->persistent()
->send();

return null; // Halt the action by not returning a URL
}
return GroupOrderResource::getUrl('edit', ['record' => $groupOrder]);
}),
I tried to add the conditional logic and notification to ->before(), but it was ignored entirely and when clicking the action, so I added this logic directly to the ->url() method. But I experience some strange behaviour, as these notifications are sent when the table is loaded, which makes sense as the url is generated before the action is clicked. But each notification is sent twice, which is odd to me. Is this due to my action code, or is filament triggering the action code twice on page load?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server