Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

[Proposal] Easy way to cancel notifications at time of sending #2648

Open
gbradley opened this issue Jun 22, 2021 · 0 comments
Open

[Proposal] Easy way to cancel notifications at time of sending #2648

gbradley opened this issue Jun 22, 2021 · 0 comments

Comments

@gbradley
Copy link

gbradley commented Jun 22, 2021

There are many scenarios where it is useful to check for certain conditions before sending a queued notification.

For example, imagine a user marking an order as "dispatched", which queues an OrderDispatched notification. If the order was marked as dispatched by mistake, there's currently no easy way to prevent the notification being sent to the appropriate channels.

There are two workarounds I know of: a) queue a Job instead, performing checks inside handle() and then dispatch the notification synchronously, or b) create a method on the notification, listen for NotificationSending events, and check for the existence of the method on the notification before it is sent.


My suggestion would be to add a new shouldBeSent($channel, $notifiable) method which would be called inside the Illuminate\Notifications\NotificationSender::shouldSendNotification() method. This allows us to add easily add custom logic for cancelling notifictions when data has changed since dispatch, without having to define a custom listener.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant