Repository navigation
[9.x] Added ability to set delay per channel based on notifiable instance - #42239
Conversation
|
Was there a reason you named the method |
|
@taylorotwell |
… notification-channel-delay
I think |
|
The reason I mentioned It would also break any current use of notifications that has the Queueable-trait as it would be calling a setter-method instead of getting the desired delays per channel |
Ah - I didn't consider that. 👍 |
|
@ehamrin got it |
…ance (laravel#42239) * Added ability to set delay per channel based on notifiable instance * Keep original ternary format * Fix styling * formatting Co-authored-by: Erik Hamrin <erik@fordonskontroll.se> Co-authored-by: Taylor Otwell <taylor@laravel.com>
We have a lot of users who don't want to receive Notification emails during the night, and some that does.
After some digging this is a solution to bypass the current behaviour:
Trying to set a delay based on a notifiable instance currently required the delay to be set in
$notification->via()as it is the last method called where the notifiable is passed through. It is however not optimal as it is set on the $original instance in NotificationSender::186, so it must be overwritten in every via-call on every notifiable.My proposal is a new method call
withDelaythat accepts the notifiable and channel as arguments which provides:To me there are only upsides, if there are database queries performed or heavy logic to resolve the delay it's only calculated once if the developer choose to match against the channel name provided. The code looks cleaner as well, the
viamethod doesn't become cluttered with delay data.It does not break the existing implementation by setting the delay prop.
Only breaking change would be if someone has implemented a withDelay function in a notification to solve something else.