PHP code example of macellan / onesignal

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

    

macellan / onesignal example snippets


// config/services.php
...
    'onesignal' => [
        'app_id' => env('ONESIGNAL_APP_ID', ''),
    ],
...

use Illuminate\Notifications\Notification;
use Macellan\OneSignal\OneSignalMessage;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return ['onesignal'];
    }

    public function toOneSignal($notifiable)
    {
        return OneSignalMessage::create()
            ->setSubject('Awesome App')
            ->setBody('Your account was approved!');  
    }
}

   public function toOneSignal($notifiable)
    {
        return OneSignalMessage::create()
            ->setAppId('Other AppId')
    }

public function routeNotificationForOneSignal()
{
    return $this->player_id;
}

Notification::route('onesignal', 'player_id')  
            ->notify(new AccountApproved());