Laravel Subscribable Notifications | Laravel News

Laravel Subscribable Notifications is a package by Andrés Santibáñez that allows you to subscribe your app’s users to your app notifications and dispatch them without specifying the recipient:

This package allows you to subscribe your app Users to your app Notifications and dispatch them without specifying the recipient. The main goal of this package is to enable you to create “lists of recipients” for your Notification classes and dispatch notifications to your users easily.

At a high level, here’s an example of how you can send a notification to multiple users using this package:

1Notification::send([$user1, $user2, $user3], new OrderShipped($order));


3// or

4$notification = new OrderShipped($order);





Setting up notifications to use this package involves using the DispatchesToSubscribers trait and a SubscribableNotification interface:

1use AsantibanezLaravelSubscribableNotificationsTraits DispatchesToSubscribers;


3class SalesOrderApprovedNotification extends Notification implements SubscribableNotification


5 use DispatchesToSubscribers;


7 public static function subscribableNotificationType(): string

8 {

9 return 'sales-order.approved';

10 }


12 // notification implementation here


This package also supports subscribing and unsubscribing notification subscriptions. Check the readme for full details on setting up and using this package. You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Source link

Latest articles

Related articles

Leave a reply

Please enter your comment!
Please enter your name here