PHP code example of daim2k5 / laravel-push-notification
1. Go to this page and download the library: Download daim2k5/laravel-push-notification library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
daim2k5 / laravel-push-notification example snippets
'providers' => array(
...
'Davibennun\LaravelPushNotification\LaravelPushNotificationServiceProvider'
)
'aliases' => array(
...
'PushNotification' => 'Davibennun\LaravelPushNotification\Facades\PushNotification'
)
php artisan vendor:publish --provider="Davibennun\LaravelPushNotification\LaravelPushNotificationServiceProvider" --tag="config"
array(
'appNameIOS'=>array(
'environment' => 'development',
'certificate' => '/path/to/certificate.pem',
'passPhrase' => 'password',
'service' => 'apns'
),
'appNameAndroid'=>array(
'environment' => 'production',
'apiKey' => 'yourAPIKey',
'service' => 'gcm'
)
);
PushNotification::app('appNameIOS')
->to($deviceToken)
->send('Hello World, i`m a push message');
//iOS app
PushNotification::app(['environment' => 'development',
'certificate' => '/path/to/certificate.pem',
'passPhrase' => 'password',
'service' => 'apns']);
//Android app
PushNotification::app(['environment' => 'production',
'apiKey' => 'yourAPIKey',
'service' => 'gcm']);
$devices = PushNotification::DeviceCollection(array(
PushNotification::Device('token', array('badge' => 5)),
PushNotification::Device('token1', array('badge' => 1)),
PushNotification::Device('token2')
));
$message = PushNotification::Message('Message Text',array(
'badge' => 1,
'sound' => 'example.aiff',
'actionLocKey' => 'Action button title!',
'locKey' => 'localized key',
'locArgs' => array(
'localized args',
'localized args',
),
'launchImage' => 'image.jpg',
'custom' => array('custom data' => array(
'we' => 'want', 'send to app'
))
));
$collection = PushNotification::app('appNameIOS')
->to($devices)
->send($message);
// get response for each device push
foreach ($collection->pushManager as $push) {
$response = $push->getAdapter()->getResponse();
}
// access to adapter for advanced settings
$push = PushNotification::app('appNameAndroid');
$push->adapter->setAdapterParameters(['sslverifypeer' => false]);