Laravel Notification Channels

News

October 23rd, 2019

laravel-notifications.jpg

Laravel Notification Channels is a collection of custom notification drivers for Laravel. With roughly thirty-nine ready-to-use channels at the time of writing, this is likely the most extensive collection of notification plugins for any framework.

The notification channels GitHub organization is a centralized place for all of the different notification packages. However, individual packages might be maintained by various authors:

We aim to provide a curated selection of notification channels for use in your Laravel applications…If we don’t have a package for your desired service yet, read on for instructions on how to contribute!

If you have an idea for a notification channel, check out the skeleton repo for creating a new notification channel. Once you are ready to contribute your channel, open a pull request to laravel-notification-channels/channels. Authors get admin access to their channel repository and an invite to the Laravel Notification Channels GitHub organization.

Here’s a quick example of an account notification from the Apple Push Notification service (APNs) documentation:

1use NotificationChannels\Apn\ApnChannel;
2use NotificationChannels\Apn\ApnMessage;
3use Illuminate\Notifications\Notification;
4 
5class AccountApproved extends Notification
6{
7 public function via($notifiable)
8 {
9 return [ApnChannel::class]; // Make sure you use ‘ApnChannel::class’, not just ‘apn’
10 }
11 
12 public function toApn($notifiable)
13 {
14 return ApnMessage::create()
15 ->badge(1)
16 ->title(‘Account approved’)
17 ->body(“Your {$notifiable->service} account was approved!);
18 }
19}

To learn more about the available channels, check out the official documentation. Each channel in the documentation has installation instructions and details on getting started.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.