Code Monkey home page Code Monkey logo

pusher-push-notifications's Introduction

Pusher push notifications channel for Laravel 5.3

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads

This package makes it easy to send Pusher push notifications with Laravel 5.3.

Contents

Installation

You can install the package via composer:

composer require laravel-notification-channels/pusher-push-notifications

You must install the service provider:

// config/app.php
'providers' => [
    ...
    NotificationChannels\PusherPushNotifications\PusherPushNotificationsServiceProvider::class,
],

Setting up your Pusher account

Before using this package you should set up a Pusher account. Here are the steps required.

  • Login to https://dashboard.pusher.com/
  • Select your app from the sidebar or create a new app.
  • Click on the "Push Notifications" tab.
  • Upload your APNS Certificate or add your GCM API key.
  • Now select the "App Keys" tab.
  • Copy your app_id, key, and secret.
  • Update the values in your config/broadcasting.php file under the pusher connection.
  • You're now good to go.

Usage

Now you can use the channel in your via() method inside the Notification class.

use NotificationChannels\PusherPushNotifications\PusherChannel;
use NotificationChannels\PusherPushNotifications\PusherMessage;
use Illuminate\Notifications\Notification;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [PusherChannel::class];
    }

    public function toPushNotification($notifiable)
    {
        return PusherMessage::create()
            ->iOS()
            ->badge(1)
            ->sound('success')
            ->body("Your {$notifiable->service} account was approved!");
    }
}

Available Message methods

  • platform(''): Accepts a string value of iOS or Android.
  • iOS(): Sets the platform value to iOS.
  • android(): Sets the platform value to Android.
  • title(''): Accepts a string value for the title.
  • body(''): Accepts a string value for the body.
  • sound(''): Accepts a string value for the notification sound file. Notice that if you leave blank the default sound value will be default.
  • icon(''): Accepts a string value for the icon file. (Android Only)
  • badge(1): Accepts an integer value for the badge. (iOS Only)
  • setOption($key, $value): Allows you to set any value in the message payload. For more information check here for iOS, or here for Android.

Sending to multiple platforms

You can send a single message to an iOS device and an Android device at the same time using the withiOS() and withAndroid() method:

public function toPushNotification($notifiable)
{
    $message = "Your {$notifiable->service} account was approved!";

    return PusherMessage::create()
        ->iOS()
        ->badge(1)
        ->body($message)
        ->withAndroid(
            PusherMessage::create()
                ->title($message)
                ->icon('icon')
        );
}
  • Notice that iOS is the default platform, which means you don't have to call ->iOS().
  • When using withAndroid() or withiOS() you don't have to define the platform, it's done behind the scenes for you.

Routing a message

By default the pusher "interest" messages will be sent to will be defined using the {notifiable}.{id} convention, for example App.User.1, however you can change this behaviour by including a routeNotificationForPusherPushNotifications() in the notifiable class method that returns the interest name.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

pusher-push-notifications's People

Contributors

casperboone avatar freekmurze avatar fwartner avatar mpociot avatar oyed avatar sebastiandedeyne avatar themsaid avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.