How to Delay notifications by channel in Laravel 8.x?
Up until now, in Laravel, if you need to delay notifications, you could do it by chaining the delay method onto your notification object like so.
$delay = now()->addMinutes(10);
$user->notify((new InvoicePaid($invoice))->delay($delay));
The issue with this is it will delay all the notification channels that are related to the notification.
This recent PR in Laravel 8.x gets help for determining delay per channel.
For example, you can specify delay per channel by passing an array to the delay method to indicate the delay amount for specific channels like so.
$user->notify((new InvoicePaid($invoice))->delay([
'mail' => now()->addMinutes(5),
'sms' => now()->addMinutes(10),
]));
Note: When utilizing an array, only channels specified in the array will get delayed. If the channel is absent in the array, it won't be delayed.
Please login or create new account to add your comment.