@@ -158,6 +158,51 @@ Segment::identify([
158158]);
159159```
160160
161+ ### Laravel Notifications
162+ This package includes an out-of-the-box notification channel, to allow you to use Laravel's built-in notification
163+ feature. To send Segment events to users as notifications, generate your notification as normal;
164+
165+ ```
166+ php artisan make:notification UserSubscribed
167+ ```
168+
169+ You must ensure your notification implements the ` CanNotifyViaSegment ` interface, and add the required ` toSegment `
170+ method. Then you can configure the ` via ` method to include the ` SegmentChannel ` class.
171+
172+ You can then adjust the ` toSegment ` method to return the event you'd like.
173+
174+ ```
175+ use Illuminate\Notifications\Notification;
176+ use SlashEquip\LaravelSegment\Contracts\CanBeIdentifiedForSegment;
177+ use SlashEquip\LaravelSegment\Contracts\CanBeSentToSegment;
178+ use SlashEquip\LaravelSegment\Contracts\CanNotifyViaSegment;
179+ use SlashEquip\LaravelSegment\Notifications\SegmentChannel;
180+ use SlashEquip\LaravelSegment\SimpleSegmentEvent;
181+
182+ class UserSubscribed extends Notification implements CanNotifyViaSegment
183+ {
184+ use Notifiable;
185+
186+ public function __construct(
187+ ) {
188+ }
189+
190+ public function via(object $notifiable): array
191+ {
192+ return [SegmentChannel::class];
193+ }
194+
195+ public function toSegment(CanBeIdentifiedForSegment $notifiable): CanBeSentToSegment
196+ {
197+ return new SimpleSegmentEvent(
198+ $notifiable,
199+ 'User Subscribed',
200+ ['some' => 'thing'],
201+ );
202+ }
203+ }
204+ ```
205+
161206## Misc
162207
163208### Deferring
@@ -167,7 +212,7 @@ through-out the request or process and then send them in batch after your applic
167212happens during the Laravel termination.
168213
169214### Safe mode
170- By default safe-mode is turned on. When safe-mode is active it will swallow any exceptions thrown when making the HTTP
215+ By default, safe-mode is turned on. When safe-mode is active it will swallow any exceptions thrown when making the HTTP
171216request to Segmenta and report them automatically to the exception handler, allow your app to continue running. When
172217disabled then the exception will be thrown.
173218
0 commit comments