PHP code example of nairanomura / notificationapi

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

    

nairanomura / notificationapi example snippets


'providers' => [
	// ...
	
	NairanOmura\NotificationApi\NotificationApiServiceProvider::class,
]

return [
   
    //...
    'notification-api' => [
        'key' => env('NOTIFICATION_API_KEY'),
        'secret' => env('NOTIFICATION_API_SECRET'),
    ]
];

public function via($notifiable)
{
    return ['notification-api'];
}

//...

public function toNotificationApi($notifiable) 
{
    return [
        "notificationId" => "notification_example",
        "user" => [
            "id" => $notifiable->getAttribute('id'),
            "email" => $notifiable->getAttribute('email'),
        ],
        "mergeTags" => [
            "userName" => auth()->user()->name,
            "clickAction" => config('app.env')."/example"
        ]
    ];
}

    class User extends Authenticatable
    {
        use Notifiable;
        //...

#notify one user
$user->notify((new SomeNotification(..)));

#notify multiple users
Notification::send($users, new SomeNotification(..);

$data = [
  "notificationId" => "order_tracking",
  "user" => [
    "id" => "[email protected]",
    "email" => "[email protected]",
    "number" => "+15005550006"
  ],
  "mergeTags" => [
    "item" => "Krabby Patty Burger",
    "address" => "124 Conch Street",
    "orderId" => "1234567890"
  ]
];

$result = notification_api($data);
#or
$result = (new NotificationApiService)->send($data)
bash
php artisan make:notification SomeNotification