Laravel One Signal is Laravel Wrapper for One Signal. One Signal is a great platform for send a push notification to your users.
Install the package by the following command,
composer require ladumor/one-signal
Run the following command to publish config file,
php artisan vendor:publish --provider="Ladumor\OneSignal\OneSignalServiceProvider"
Add the provider to your config/app.php
into provider
section if using lower version of laravel,
Ladumor\OneSignal\OneSignalServiceProvider::class,
Add the Facade to your config/app.php
into aliases
section,
'OneSignal' => \Ladumor\OneSignal\OneSignal::class,
For send push notification, use the sendPush method by calling,
$fields['include_player_ids'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];
$message = 'hey!! this is test push.!'
\OneSignal::sendPush($fields, $message);
You can customise a contents and pass it in fields. message does not required when you pass contents
$fields['include_player_ids'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];
$fields['contents'] = array(
"en" => 'English Message',
"es" => 'Spanish Message',
);
\OneSignal::sendPush($fields);
For retrieve all notifications, use the getNotifications
method by calling,
OneSignal::getNotifications();
You can check here return response format.
For retrieve single notification, use the getNotification
method with id param by calling,
OneSignal::getNotification($notificationId);
You can check here return response format.
For retrieve all user devices, use the getDevices
method by calling,
OneSignal::getDevices();
You can check here return response format.
For retrieve single Devices, use the getDevice
method with id param by calling,
OneSignal::getDevice($deviceId);
You can check here return response format.
For add a device in your application, use the addDevice
method by calling, if you want to create device in different application than you can specify app_id
in $fields
array.
$fields = [
'device_type' => 0,
'identifier' => '7abcd558f29d0b1f048083e2834ad8ea4b3d87d8ad9c088b33c132706ff445f0',
'timezone' => '-28800',
'game_version' => '1.1',
'device_os' => '7.0.4',
'test_type' => 1,
'device_model' => "iPhone 8,2",
'tags' => array("foo" => "bar")
];
return OneSignal::addDevice($fields);
You can check here supported parameters and guide.
For update a device in your application, use the addDevice
method by calling, if you want to update device in different application than you can specify app_id
in $fields
array.
$fields = [
'device_type' => 0,
'identifier' => '7abcd558f29d0b1f048083e2834ad8ea4b3d87d8ad9c088b33c132706ff445f0',
'timezone' => '-28800',
'game_version' => '1.1',
'device_os' => '7.0.4',
'test_type' => 1,
'device_model' => "iPhone 8,2",
'tags' => array("foo" => "bar")
];
$playerId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
return OneSignal::updateDevice($fields, $playerId);
You can check here supported parameters and guide.
NOTE: REQUIRED ONE-SIGNAL PAID PLAN
For add a new segment in your application, use the createSegment
method by calling,
$fields = [
'name' => 'iOS, Android, Web',
"filters" => array("field" => "device_type", "relation" => "=", "value" => "Android"),
];
return OneSignal::createSegment($fields);
You can check here supported parameters and guide.
OneSignal::deleteSegment('YOUR_SEGMENT_ID')
NOTE: REQUIRED ONE-SIGNAL PAID PLAN
You can check here for more guide.
Note*: Auth key must be set in one-signal.php
how to get auth_key?
View the details of all of your current OneSignal apps
$apps = OneSignal::getApps();
You can check here api response.
View the details of single of your current OneSignal app or other app by passing app id.
// It's return default site which is configured in config.
$app = OneSignal::getApp();
// you can specify app id as wel but it's optional
$app = OneSignal::getApp('YOUR_APP_ID');
You can check here api response.
Creates a new OneSignal app.
$fields = array(
'name' => "TestByMe"
);
OneSignal::createApp($fields);
You can check here supported parameters and guide.
Update a new OneSignal app.
$fields = array(
'name' => "TestByMe"
);
OneSignal::updateApp($fields);
// you can pass second param as a appId if you want to update other app.. default take from config.
You can check here supported parameters and guide.
Please see Change Log here
The MIT License (MIT). Please see License File for more information