Skip to content

Commit 3f53d0a

Browse files
[11.x] Write documentation for notification middleware (laravel#9594)
* Write documentation for notification middleware * Make code block stylign align with rest of docs * More little markdown tweaks * Minor wording tweaks * formatting * Formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 2c81d29 commit 3f53d0a

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

notifications.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,6 @@ If you would like to delay the delivery of the notification, you may chain the `
169169

170170
$user->notify((new InvoicePaid($invoice))->delay($delay));
171171

172-
<a name="delaying-notifications-per-channel"></a>
173-
#### Delaying Notifications per Channel
174-
175172
You may pass an array to the `delay` method to specify the delay amount for specific channels:
176173

177174
$user->notify((new InvoicePaid($invoice))->delay([
@@ -253,6 +250,27 @@ If you would like to specify a specific queue that should be used for each notif
253250
];
254251
}
255252

253+
<a name="queued-notification-middleware"></a>
254+
#### Queued Notification Middleware
255+
256+
Queued notifications may define middleware [just like queued jobs](/docs/{{version}}/queues#job-middleware). To get started, define a `middleware` method on your notification class. The `middleware` method will receive `$notifiable` and `$channel` variables, which allow you to customize the returned middleware based on the notification's destination:
257+
258+
use Illuminate\Queue\Middleware\RateLimited;
259+
260+
/**
261+
* Get the middleware the notification job should pass through.
262+
*
263+
* @return array<int, object>
264+
*/
265+
public function middleware(object $notifiable, string $channel)
266+
{
267+
return match ($channel) {
268+
'email' => [new RateLimited('postmark')],
269+
'slack' => [new RateLimited('slack')],
270+
default => [],
271+
};
272+
}
273+
256274
<a name="queued-notifications-and-database-transactions"></a>
257275
#### Queued Notifications and Database Transactions
258276

0 commit comments

Comments
 (0)