how to trigger notification on a custom bulkaction?

Tables\Actions\BulkAction::make('toggleStatus')
->label('Toggle Status')
->icon('heroicon-o-arrow-path')
->requiresConfirmation()
->action(function (Collection $records) {
$records->each(function (User $user) {
$user->update(['is_active' => !$user->is_active]);
});
})
->deselectRecordsAfterCompletion()
->successNotification(
Notification::make()
->success()
->title('User status updated')
->body('The selected users\' statuses have been toggled.')
),
Tables\Actions\BulkAction::make('toggleStatus')
->label('Toggle Status')
->icon('heroicon-o-arrow-path')
->requiresConfirmation()
->action(function (Collection $records) {
$records->each(function (User $user) {
$user->update(['is_active' => !$user->is_active]);
});
})
->deselectRecordsAfterCompletion()
->successNotification(
Notification::make()
->success()
->title('User status updated')
->body('The selected users\' statuses have been toggled.')
),
Solution:
you can just move notification to action like this ```php ->action(function (Collection $records) { $records->each(function (User $user) { $user->update(['is_active' => !$user->is_active]);...
Jump to solution
2 Replies
Solution
darkclow4
darkclow43mo ago
you can just move notification to action like this
->action(function (Collection $records) {
$records->each(function (User $user) {
$user->update(['is_active' => !$user->is_active]);
});

Notification::make()
->success()
->title('User status updated')
->body('The selected users\' statuses have been toggled.')
->send();
})
->action(function (Collection $records) {
$records->each(function (User $user) {
$user->update(['is_active' => !$user->is_active]);
});

Notification::make()
->success()
->title('User status updated')
->body('The selected users\' statuses have been toggled.')
->send();
})
Rolland
RollandOP3mo ago
Thank you. that solved the problem!
Want results from more Discord servers?
Add your server