Laravel - Notifications - Queueing Notifications

Before queueing notifications you should configure your queue and start a worker.

Sending notifications can take time, especially if the channel needs to make an external API call to deliver the notification. To speed up your application's response time, let your notification be queued by adding the ShouldQueue interface and Queueable trait to your class. The interface and trait are already imported for all notifications generated using the make:notification command, so you may immediately add them to your notification class:

    
    

Once the ShouldQueue interface has been added to your notification, you may send the notification like normal. Laravel will detect the ShouldQueue interface on the class and automatically queue the delivery of the notification:

    
    $user->notify(new InvoicePaid($invoice));
	

If you would like to delay the delivery of the notification, you may chain the delay method onto your notification instantiation:

    
    $delay = now()->addMinutes(10);
    
    $user->notify((new InvoicePaid($invoice))->delay($delay));
	

You may pass an array to the delay method to specify the delay amount for specific channels:

    
    $user->notify((new InvoicePaid($invoice))->delay([
        'mail' => now()->addMinutes(5),
        'sms' => now()->addMinutes(10),
    ]));
	

When queueing notifications, a queued job will be created for each recipient and channel combination. For example, six jobs will be dispatched to the queue if your notification has three recipients and two channels.