PHP code example of berkayk / onesignal-laravel

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

    

berkayk / onesignal-laravel example snippets


'providers' => [
	// ...
	Berkayk\OneSignal\OneSignalServiceProvider::class
];

'aliases' => [
	// ...
	'OneSignal' => Berkayk\OneSignal\OneSignalFacade::class
];

    OneSignal::sendNotificationToAll(
        "Some Message", 
        $url = null, 
        $data = null, 
        $buttons = null, 
        $schedule = null
    );

    OneSignal::sendNotificationUsingTags(
        "Some Message",
        array(
            ["field" => "tag", "key" => "email", "relation" => "=", "value" => "[email protected]"],
            ["field" => "tag", "key" => "email", "relation" => "=", "value" => "[email protected]"],
            ...
        ),
        $url = null,
        $data = null,
        $buttons = null,
        $schedule = null
    );

    OneSignal::sendNotificationUsingTags(
        "Some Message",
        array(
            ["field" => "tag", "key" => "session_count", "relation" => ">", "value" => '2'],
            ["field" => "tag", "key" => "first_session", "relation" => ">", "value" => '2000'],
        ),
        $url = null,
        $data = null,
        $buttons = null,
        $schedule = null
    );

    OneSignal::sendNotificationToUser(
        "Some Message",
        $userId,
        $url = null,
        $data = null,
        $buttons = null,
        $schedule = null
    );

    OneSignal::sendNotificationToExternalUser(
        "Some Message",
        $userId,
        $url = null,
        $data = null,
        $buttons = null,
        $schedule = null
    );

    OneSignal::sendNotificationToSegment(
        "Some Message",
        $segment,
        $url = null,
        $data = null,
        $buttons = null,
        $schedule = null
    );

    OneSignal::sendNotificationCustom($parameters);

    OneSignal::async()->sendNotificationCustom($parameters);

use OneSignal;

$params = [];
$params['android_accent_color'] = 'FFCCAA72'; // argb color value
$params['small_icon'] = 'ic_stat_distriqt_default'; // icon res name specified in your app

$message = "Test message to send";
$segment = "Testers";
OneSignal::addParams($params)->sendNotificationToSegment(
                $message,
                $segment
            );

// or to all users 
OneSignal::addParams($params)->sendNotificationToAll($message);


use OneSignal;

$message = "Test message to send";
$segment = "Testers";
OneSignal::setParam('priority', 10)->sendNotificationToSegment(
                $message,
                $segment
            );

// You can chain as many parameters as you wish

OneSignal::setParam('priority', 10)->setParam('small_icon', 'ic_stat_onesignal_default')->setParam('led_color', 'FFAACCAA')->sendNotificationToAll($message);


use OneSignal;

OneSignal::sendNotificationToSegment(
                "Test message with custom heading and subtitle",
                "Testers", 
                null, null, null, null, 
                "Custom Heading", 
                "Custom subtitle"
            );

use OneSignal;

$userId = "3232331-1722-4fee-943d-23123asda123"; 
$params = []; 
$params['$params['contents'] = $contents; 
$params['delayed_option'] = "timezone"; // Will deliver on user's timezone 
$params['delivery_time_of_day'] = "2:30PM"; // Delivery time

OneSignal::sendNotificationCustom($params);


php artisan vendor:publish --provider="Berkayk\OneSignal\OneSignalServiceProvider" --tag="config"