PHP code example of laravel-notification-channels / apn

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

    

laravel-notification-channels / apn example snippets


'connections' => [
    'apn' => [
        'key_id' => env('APN_KEY_ID'),
        'team_id' => env('APN_TEAM_ID'),
        'app_bundle_id' => env('APN_BUNDLE_ID'),
        // Enable either `private_key_path` or `private_key_content` depending on your environment
        // 'private_key_path' => env('APN_PRIVATE_KEY'),
        'private_key_content' => env('APN_PRIVATE_KEY'),
        'private_key_secret' => env('APN_PRIVATE_SECRET'),
        'production' => env('APN_PRODUCTION', true),
    ],
],

'connections' => [
    'apn' => [
        'app_bundle_id' => env('APN_BUNDLE_ID'),
        'certificate_path' => env('APN_CERTIFICATE_PATH'),
        'certificate_secret' => env('APN_CERTIFICATE_SECRET'),
        'production' => env('APN_PRODUCTION', true),
    ],
],

use NotificationChannels\Apn\ApnChannel;
use NotificationChannels\Apn\ApnMessage;
use Illuminate\Notifications\Notification;

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

    public function toApn($notifiable)
    {
        return ApnMessage::create()
            ->badge(1)
            ->title('Account approved')
            ->body("Your {$notifiable->service} account was approved!");
    }
}

public function routeNotificationForApn()
{
    return $this->apn_token;
}

$customClient = new Pushok\Client(Pushok\AuthProvider\Token::create($options));

return ApnMessage::create()
    ->title('Account approved')
    ->body("Your {$notifiable->service} account was approved!")
    ->via($customClient)

use NotificationChannels\Apn\ApnVoipChannel;
use NotificationChannels\Apn\ApnVoipMessage;
use Illuminate\Notifications\Notification;

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

    public function toApnVoip($notifiable)
    {
        return ApnVoipMessage::create()
            ->badge(1);
    }
}

public function routeNotificationForApnVoip()
{
    return $this->apn_voip_token;
}