|
| 1 | +# OneSignal Push Notifications for Laravel 5 |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This is a simple OneSignal wrapper library for Laravel. It simplifies the basic notification flow with the defined methods. You can send a message to all users or you can notify a single user. |
| 6 | +Before you start installing this service, please complete your OneSignal setup at https://onesignal.com and finish all the steps that is necessary to obtain an application id and REST API Keys. |
| 7 | + |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +First, you'll need to require the package with Composer: |
| 12 | + |
| 13 | +```sh |
| 14 | +composer require Liliom/onesignal-laravel |
| 15 | +``` |
| 16 | + |
| 17 | +Aftwards, run `composer update` from your command line. |
| 18 | + |
| 19 | +Then, update `config/app.php` by adding an entry for the service provider. |
| 20 | + |
| 21 | +```php |
| 22 | +'providers' => [ |
| 23 | + // ... |
| 24 | + Liliom\OneSignal\OneSignalServiceProvider::class |
| 25 | +]; |
| 26 | +``` |
| 27 | + |
| 28 | + |
| 29 | +Then, register class alias by adding an entry in aliases section |
| 30 | + |
| 31 | +```php |
| 32 | +'aliases' => [ |
| 33 | + // ... |
| 34 | + 'OneSignal' => Liliom\OneSignal\OneSignalFacade::class |
| 35 | +]; |
| 36 | +``` |
| 37 | + |
| 38 | + |
| 39 | +Finally, from the command line again, run |
| 40 | + |
| 41 | +``` |
| 42 | +php artisan vendor:publish --tag=config |
| 43 | +``` |
| 44 | + |
| 45 | +to publish the default configuration file. |
| 46 | +This will publish a configuration file named `onesignal.php` which includes your OneSignal authorization keys. |
| 47 | + |
| 48 | +> **Note:** If the previous command does not publish the config file successfully, please check the steps involving *providers* and *aliases* in the `config/app.php` file. |
| 49 | +
|
| 50 | + |
| 51 | +## Configuration |
| 52 | + |
| 53 | +You need to fill in `onesignal.php` file that is found in your applications `config` directory. |
| 54 | +`app_id` is your *OneSignal App ID* and `rest_api_key` is your *REST API Key*. |
| 55 | + |
| 56 | +## Usage |
| 57 | + |
| 58 | +### Sending a Notification To All Users |
| 59 | + |
| 60 | +You can easily send a message to all registered users with the command |
| 61 | + |
| 62 | + OneSignal::sendNotificationToAll("Some Message", $url = null, $data = null, $buttons = null, $schedule = null); |
| 63 | + |
| 64 | +`$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url. |
| 65 | + |
| 66 | + |
| 67 | +### Sending a Notification based on Tags/Filters |
| 68 | + |
| 69 | +You can send a message based on a set of tags with the command |
| 70 | + |
| 71 | + OneSignal::sendNotificationUsingTags("Some Message", array("key" => "device_uuid", "relation" => "=", "value" => 123e4567-e89b-12d3-a456-426655440000), $url = null, $data = null, $buttons = null, $schedule = null); |
| 72 | + |
| 73 | + |
| 74 | +### Sending a Notification To A Specific User |
| 75 | + |
| 76 | +After storing a user's tokens in a table, you can simply send a message with |
| 77 | + |
| 78 | + OneSignal::sendNotificationToUser("Some Message", $userId, $url = null, $data = null, $buttons = null, $schedule = null); |
| 79 | + |
| 80 | +`$userId` is the user's unique id where he/she is registered for notifications. Read https://documentation.onesignal.com/docs/web-push-tagging-guide for additional details. |
| 81 | +`$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url. |
| 82 | + |
| 83 | + |
| 84 | +### Sending a Notification To Segment |
| 85 | + |
| 86 | +You can simply send a notification to a specific segment with |
| 87 | + |
| 88 | + OneSignal::sendNotificationToSegment("Some Message", $segment, $url = null, $data = null, $buttons = null, $schedule = null); |
| 89 | + |
| 90 | +`$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url. |
| 91 | + |
| 92 | +### Sending a Custom Notification |
| 93 | + |
| 94 | +You can send a custom message with |
| 95 | + |
| 96 | + OneSignal::sendNotificationCustom($parameters); |
| 97 | + |
| 98 | + ### Sending a Custom Notification |
| 99 | +### Sending a async Custom Notification |
| 100 | +You can send a async custom message with |
| 101 | + |
| 102 | + OneSignal::async()->sendNotificationCustom($parameters); |
| 103 | + |
| 104 | +Please refer to https://documentation.onesignal.com/reference for all customizable parameters. |
| 105 | + |
0 commit comments