Skip to content

Commit 228216f

Browse files
stopListeningForNotification (#10835)
* Update broadcasting.md * Update broadcasting.md --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent f3cdaf3 commit 228216f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

broadcasting.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,3 +1697,22 @@ channel().notification((notification) => {
16971697
```
16981698
16991699
In this example, all notifications sent to `App\Models\User` instances via the `broadcast` channel would be received by the callback. A channel authorization callback for the `App.Models.User.{id}` channel is included in your application's `routes/channels.php` file.
1700+
1701+
<a name="stop-listening-for-notifications"></a>
1702+
#### Stop Listening for Notifications
1703+
1704+
If you would like to stop listening to notifications without [leaving the channel](#leaving-a-channel), you may use the `stopListeningForNotification` method:
1705+
1706+
```js
1707+
const callback = (notification) => {
1708+
console.log(notification.type);
1709+
}
1710+
1711+
// Start listening...
1712+
Echo.private(`App.Models.User.${userId}`)
1713+
.notification(callback);
1714+
1715+
// Stop listening (callback must be the same)...
1716+
Echo.private(`App.Models.User.${userId}`)
1717+
.stopListeningForNotification(callback);
1718+
```

0 commit comments

Comments
 (0)