New Community Project: Laravel Notification Channels


August 12th, 2016

New Community Project: Laravel Notification Channels

Laravel 5.3 will ship with a notification system that includes a Nexmo SMS driver, a Mail driver, and the ability to include custom drivers. Now that we have this system built-in we can use the new Pusher service from inside our Laravel applications.

All we need to do is to create a custom driver and that’s it, we’ll be able to send Push notifications to our Mobile devices right away.

With the help of Freek Van der Herten and Marcel Pociot we managed to build an easy to use driver for Pusher Push Notifications.

Pusher, a real-time communication platform, has recently introduced an all-new FREE service for application developers, it’s a unified API to send native Push Notifications to iOS and Android devices.

Using native Push Notifications allows you to communicate with your users even when the app is closed or inactive, this has a great effect on user engagement.

Being able to send iOS and Android Push Notifications using a unified API saves the hassle of having to apply multiple setup procedures. All you have to do is to upload your APNS certificate for iOS devices or add your GCM API key for android devices, and that’s it.

Using this driver you’ll be able to send push notifications like this:

1class AccountApproved extends Notification
3 public function via($notifiable)
4 {
5 return [Channel::class];
6 }
8 public function toPushNotification($notifiable)
9 {
10 return (new Message())
11 ->iOS()
12 ->badge(1)
13 ->sound('success')
14 ->body("Your {$notifiable->service} account was approved!");
15 }

This driver will allow you to send Push Notifications with a fluent expressive Laravel-style syntax.

You may check it out here.

Building custom drivers

There are many platforms that send notifications, and with the new system in Laravel 5.3 we believe that it’s a good idea to collect all the custom drivers in a single place, just as is a one-stop-shop for all Socialite Providers, for that we created a GitHub organization where we’ll collect and host all custom drivers.

It’s still in the making but contributions are most welcomed if you have an idea for a custom channel, please check this skeleton repo where you can use as boilerplate.

Filed in:

Mohamed Said

Web Developer and Laravel Core Contributor