PHP code example of shokme / laravel-onesignal

1. Go to this page and download the library: Download shokme/laravel-onesignal 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/ */

    

shokme / laravel-onesignal example snippets


$response = OneSignal::make()
    ->subject('Notification Title')
    ->contents(['en' => 'Notification Body', 'es' => 'Translated Notification Body'])
    ->url('en.myapp.service://')
    ->sendTo(SignalType::Users, [1, 2, 3]);

OneSignal::subject('Notification Title'); // ['en' => 'Notification Title']
OneSignal::subject(['en' => 'Notification Title', 'nl' => 'Translated Notification Title']);

OneSignal::url('https://example.com');

OneSignal::buttons(ButtonType::Mobile, [
    ['id' => 'action-1', 'text' => 'Action To Trigger'],
    ...
]);

OneSignal::buttons(ButtonType::Web, [
    ['id' => 'action-1', 'text' => 'Action To Trigger', 'url' => 'https://app.com'],
    ...
]);

OneSignal::parameters(['template_id' => 'be4a8044-bbd6-11e4-a581-000c2940e62c'])

OneSignal::schedule(Carbon::parse('17 april 2022')->timezone('GMT+3'));

$lastActive = OneSignal::delay(Delay::LastActive);
$timezone = OneSignal::delay(Delay::Timezone, '9:00AM');

OneSignal::channel(Channel::Sms);

OneSignal::channels([Channel::Sms, Channel::Push]);

OneSignal::filters([
    ['field' => 'tag', 'key' => 'test', 'relation' => '=', 'value' => 'test'],
    ['field' => 'tag', 'key' => 'test2', 'relation' => '>=', 'value' => 'test2'],
])

OneSignal::filter('tag', 'level', 10)
    ->filter('amount_spent', '>', 0)
    ->filter('session_count', 5);

//[
//    ['field' => 'tag', 'key' => 'test', 'relation' => '=', 'value' => 10],
//    ['field' => 'amount_spent', 'relation' => '>=', 'value' => '0'],
//    ['field' => 'session_count', 'relation' => '=', 'value' => '5'],
//]

$response = OneSignal::sendTo(SignalType::All);
$response = OneSignal::sendTo(SignalType::Users, [1,2,3]);
$response = OneSignal::channel(Channel::Sms)->sendTo(SignalType::Players, ['player_id-1', 'player_id-2']);
$response = OneSignal::sendTo(SignalType::Segments, ['Active Users', 'Inactive Users']);
$response = OneSignal::filters([...])->sendTo(SignalType::Filters);

$response = OneSignal::getNotifications();
// Dashboard, Api or Automated
$response = OneSignal::getNotifications(Kind::Dashboard);

$response = OneSignal::getNotification('notification_id');

$response = OneSignal::cancel('notification_id');

$response = OneSignal::addPlayer(DeviceType::Android, 'push-token-from-google', 'Australia/Sydney', [
    'device_model' => 'Nexus 5X',
]);

$response = OneSignal::editPlayer('push-token-from-google', timezone: 'Europe/Brussels');
shell
php artisan vendor:publish --provider="Shokme\OneSignal\OneSignalServiceProvider" --tag="config"