Alymosul / laravel-exponent-push-notifications by Alymosul
forked from laravel-notification-channels/channels

Exponent push notifications driver for laravel
578,859
145
6
Package Data
Maintainer Username: Alymosul
Maintainer Contact: alymosul@gmail.com (Aly Suleiman)
Package Create Date: 2017-07-08
Package Last Update: 2024-03-02
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-23 03:02:55
Package Statistics
Total Downloads: 578,859
Monthly Downloads: 10,491
Daily Downloads: 307
Total Stars: 145
Total Watchers: 6
Total Forks: 77
Total Open Issues: 9

Exponent push notifications channel for Laravel 5

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

Contents

Installation

You can install the package via composer:

composer require alymosul/laravel-exponent-push-notifications

If you are using Laravel 5.5 or higher this package will automatically register itself using Package Discovery. For older versions of Laravel you must install the service provider manually:

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

Before publish exponent notification migration you must add in .env file:

EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER=database

You can publish the migration with:

php artisan vendor:publish --provider="NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider" --tag="migrations"

After publishing the migration you can create the exponent_push_notification_interests table by running the migrations:

php artisan migrate

You can optionally publish the config file with:

php artisan vendor:publish --provider="NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider" --tag="config"

This is the contents of the published config file:

return [
    'interests' => [
        /*
         * Supported: "file", "database"
         */
        'driver' => env('EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER', 'file'),

        'database' => [
            'table_name' => 'exponent_push_notification_interests',
        ],
    ]
];

Usage

use NotificationChannels\ExpoPushNotifications\ExpoChannel;
use NotificationChannels\ExpoPushNotifications\ExpoMessage;
use Illuminate\Notifications\Notification;

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

    public function toExpoPush($notifiable)
    {
        return ExpoMessage::create()
            ->badge(1)
            ->enableSound()
            ->body("Your {$notifiable->service} account was approved!");
    }
}

Available Message methods

A list of all available options

  • body(''): Accepts a string value for the body.
  • enableSound(): Enables the notification sound.
  • disableSound(): Mutes the notification sound.
  • badge(1): Accepts an integer value for the badge.
  • ttl(60): Accepts an integer value for the time to live.

Managing Recipients

This package registers two endpoints that handle the subscription of recipients, the endpoints are defined in src/Http/routes.php file, used by ExpoController and all loaded through the package service provider.

Routing a message

By default the exponent "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 routeNotificationForExpoPushNotifications() 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 alymosul@gmail.com 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.