PHP code example of brdevelopers / laravel-apn-notification-channel

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

    

brdevelopers / laravel-apn-notification-channel example snippets


// config/app.php
'providers' => [
    // ...
    BRDevelopers\ApnNotificationChannel\ApnServiceProvider::class,
],

// config/broadcasting.php
'connections' => [
    ...
    'apn' => [
        'driver' => 'jwt',
        'is_production' => env('APP_ENV') === 'production',
        'key_id' => env('APN_KEY_ID'), // The Key ID of the p8 file (available at https://developer.apple.com/account/ios/authkey/)
        'team_id' => env('APN_TEAM_ID'), // The Team ID of your Apple Developer Account (available at https://developer.apple.com/account/#/membership/)
        'app_bundle_id' => env('APN_APP_BUNDLE_ID'), // The Bundle ID of your application. For example, "com.company.application"
        'private_key_path' => env('APN_PRIVATE_KEY', storage_path('apns-private-key.p8')),
        'private_key_secret' => env('APN_PRIVATE_KEY_SECRET'),
    ],
    ...
],

// config/broadcasting.php
'connections' => [
    ...
    'apn' => [
        'driver' => 'certificate',
        'is_production' => env('APP_ENV') === 'production',
        'certificate_path' => env('APN_CERTIFICATE_PATH', storage_path('apns-certificate.pem')),
        'certificate_secret' => env('APN_CERTIFICATE_SECRET'),
    ],
    ...
],

use Illuminate\Notifications\Notification;
use BRDevelopers\ApnNotificationChannel\ApnMessage;

class AccountApproved extends Notification
{
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['apn'];
    }

    /**
     * Get the APN representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return ApnMessage
     */
    public function toApn($notifiable)
    {
        return ApnMessage::create()
            ->badge(1)
            ->title('Account approved')
            ->body("Your {$notifiable->service} account was approved!");
    }
}

/**
 * Route notifications for the APN channel.
 *
 * @return string|array
 */
public function routeNotificationForApn()
{
    return $this->apn_token;
}