|
1 | | -# expo |
2 | | -Expo Notifications Channel for Laravel |
| 1 | +# Expo Push Notifications Channel |
| 2 | + |
| 3 | +[](https://packagist.org/packages/laravel-notification-channels/expo) |
| 4 | +[](LICENSE.md) |
| 5 | +[](https://travis-ci.org/laravel-notification-channels/expo) |
| 6 | +[](https://styleci.io/repos/:style_ci_id) |
| 7 | +[](https://insight.sensiolabs.com/projects/:sensio_labs_id) |
| 8 | +[](https://scrutinizer-ci.com/g/laravel-notification-channels/expo) |
| 9 | +[](https://scrutinizer-ci.com/g/laravel-notification-channels/expo/?branch=master) |
| 10 | +[](https://packagist.org/packages/laravel-notification-channels/expo) |
| 11 | + |
| 12 | +This package makes it easy to send notifications using [Expo](https://docs.expo.io/push-notifications/overview/) with Laravel 8.x |
| 13 | + |
| 14 | +## Contents |
| 15 | + |
| 16 | +- [Installation](#installation) |
| 17 | + - [Setting up the Expo service](#setting-up-the-Expo-service) |
| 18 | +- [Usage](#usage) |
| 19 | + - [Available Message methods](#available-message-methods) |
| 20 | +- [Changelog](#changelog) |
| 21 | +- [Testing](#testing) |
| 22 | +- [Security](#security) |
| 23 | +- [Contributing](#contributing) |
| 24 | +- [Credits](#credits) |
| 25 | +- [License](#license) |
| 26 | + |
| 27 | + |
| 28 | +## Installation |
| 29 | + |
| 30 | +Install this package with Composer: |
| 31 | + |
| 32 | + composer require laravel-notification-channels/expo |
| 33 | + |
| 34 | +### Setting up the Expo service |
| 35 | + |
| 36 | +If you use an [Expo Access Token](https://docs.expo.io/push-notifications/sending-notifications/#additional-security) please set this in your environment. |
| 37 | + |
| 38 | + EXPO_ACCESS_TOKEN=mysecrettoken |
| 39 | + |
| 40 | +## Usage |
| 41 | +Firstly you will need to define a method to retrieve your Expo push token |
| 42 | +````php |
| 43 | +class NotifiableModel extends Model { |
| 44 | + // You may pass a single token |
| 45 | + public function routeNotificationForExpo($notification) |
| 46 | + { |
| 47 | + return "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]" |
| 48 | + } |
| 49 | + |
| 50 | + // Or you may return an array of tokens, for example, a user could have multiple devices. |
| 51 | + public function routeNotificationForExpo($notification) |
| 52 | + { |
| 53 | + return $this->installations->pluck('expo_token')->toArray() |
| 54 | + } |
| 55 | +} |
| 56 | +```` |
| 57 | + |
| 58 | + |
| 59 | +````php |
| 60 | +<?php |
| 61 | + |
| 62 | +namespace App\Notifications; |
| 63 | + |
| 64 | +use App\Models\Message; |
| 65 | +use Illuminate\Bus\Queueable; |
| 66 | +use Illuminate\Notifications\Notification; |
| 67 | +use NotificationChannels\Expo\ExpoChannel; |
| 68 | +use NotificationChannels\Expo\ExpoMessage; |
| 69 | + |
| 70 | +class NewMessageNotification extends Notification |
| 71 | +{ |
| 72 | + use Queueable; |
| 73 | + |
| 74 | + private Message $message; |
| 75 | + |
| 76 | + public function __construct(Message $message) |
| 77 | + { |
| 78 | + $this->message = $message; |
| 79 | + } |
| 80 | + |
| 81 | + public function via($notifiable) |
| 82 | + { |
| 83 | + return [ExpoChannel::class]; |
| 84 | + } |
| 85 | + |
| 86 | + public function toExpo($notifiable) |
| 87 | + { |
| 88 | + return ExpoMessage::create() |
| 89 | + ->title("New Message from {$this->message->from}!") |
| 90 | + ->body($this->message->text) |
| 91 | + ->badge(1); |
| 92 | + } |
| 93 | +} |
| 94 | +```` |
| 95 | + |
| 96 | +### Available Message methods |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +## Changelog |
| 101 | + |
| 102 | +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. |
| 103 | + |
| 104 | +## Testing |
| 105 | + |
| 106 | + $ composer test |
| 107 | + |
| 108 | +## Security |
| 109 | + |
| 110 | +If you discover any security related issues, please email [email protected] instead of using the issue tracker. |
| 111 | + |
| 112 | +## Contributing |
| 113 | + |
| 114 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 115 | + |
| 116 | +## Credits |
| 117 | + |
| 118 | +- [Nick Pratley](https://github.com/nicko170) |
| 119 | +- [All Contributors](../../contributors) |
| 120 | + |
| 121 | +## License |
| 122 | + |
| 123 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments