Downloads
Stars
Version
This project, widely inspired by Berkayk (https://github.com/berkayk/laravel-onesignal), is another one OneSignal wrapper for Laravel. The main purpose is to make web push notifications easier. Before using this service, you'll need to complete all steps of your OneSignal setup (https://onesignal.com) to get your Application ID and API keys.
composer require okn/laravel-onesignal
config/app.php
'providers' => [
// ...
Okn\OneSignal\OneSignalServiceProvider::class
];
'aliases' => [
// ...
'OneSignal' => Okn\OneSignal\Facades\OneSignal::class
];
php artisan onesignal:install
This command will create a default config file config/onesignal.php
.
App ID et API keys must be defined in the .env
file as follow:
ONESIGNAL_APP_ID=
ONESIGNAL_REST_API_KEY=
ONESIGNAL_USER_AUTH_KEY=
$notification = OneSignal::createNotification([
'headings'=>'Title',
'contents'=>'Notification message...',
'url'=>'https://yourwebsite.com'
]);
$notification->send(['segments'=>['SEGMENT-NAME']]);
$notification->send(['ids'=>['PLAYER-ID-1','PLAYER-ID-2','PLAYER-ID-3']]);
$promise = $notification->async()->send([$params]);
This will return a GuzzleHttp\Promise\Promise
(http://docs.guzzlephp.org/en/stable/quickstart.html#async-requests)
$notification->withButtons([
[
'id' => 'btnId1',
'text' => 'Webpush button test',
'icon' => 'https://yourwebsite.com/images/icon1.png',
'url' => 'https://yourwebsite.com/action1'
],
[
'id' => 'btnId2',
'text' => 'Webpush button test #2',
'icon' => 'https://yourwebsite.com/images/icon2.png',
'url' => 'https://yourwebsite.com/action2'
]
])->send([$params]);
OneSignal::test();
This method also accepts the same argument as the method send()
.
OneSignal::getUsers(300, 0);
The first argument is the maximum limit, and the second is the offset. Both are optional.
OneSignal::getUser('PLAYER-ID');
cURL error 60: SSL certificate problem...
cURL need an SSL certificate to communicate through https protocol.
Assuming you are using WAMP on Windows:
C:\Users\[MY-USERNAME]\cacert.pem
)php.ini
to add the path to the certificatecurl.cainfo = "C:\Users\[MY-USERNAME]\cacert.pem"
Now it should works, if it doesn't you might try the next solution.
In .env
file you can add the following line:
ONESIGNAL_SSL_VERIFY=false