Delaying notifications channel-wise in Laravel 8.x
Up until now, if you would need to delay notifications, you could do it by chaining the
delay method onto your notification instantiation like so.
$delay = now()->addMinutes(10); $user->notify((new InvoicePaid($invoice))->delay($delay));
The problem with this is it will delay all the notification channels which has been associated with the notifications.
But thanks to a recent PR in Laravel 8.x which bring in the support for specifying delay per channel.
For instance, you can specify delay per channel by passing an array to the
delay method to specify the delay amount for specific channels like so.
$user->notify((new InvoicePaid($invoice))->delay([ 'mail' => now()->addMinutes(5), 'sms' => now()->addMinutes(10), ]));
Interesting thing here to note is when using array, only channels specified in the array will get delayed. If a channel is not present in the array, it won’t be delayed.
👋 Hi there! I'm Amit. I write articles about all things web development. If you like what I write and want me to continue doing the same, I would like you buy me some coffees. I'd highly appreciate that. Cheers!