PHP code example of laravel-notification-channels / aws-sns

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




return [

    // ...

    'sns' => [
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
    ],

];



use NotificationChannels\AwsSns\SnsChannel;
use NotificationChannels\AwsSns\SnsMessage;
use Illuminate\Notifications\Notification;

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

    public function toSns($notifiable)
    {
        // You can just return a plain string:
        return "Your {$notifiable->service} account was approved!";
        
        // OR explicitly return a SnsMessage object passing the message body:
        return new SnsMessage("Your {$notifiable->service} account was approved!");
        
        // OR return a SnsMessage passing the arguments via `create()` or `__construct()`:
        return SnsMessage::create([
            'body' => "Your {$notifiable->service} account was approved!",
            'transactional' => true,
            'sender' => 'MyBusiness',
        ]);

        // OR create the object with or without arguments and then use the fluent API:
        return SnsMessage::create()
            ->body("Your {$notifiable->service} account was approved!")
            ->promotional()
            ->sender('MyBusiness');
    }
}



use Illuminate\Notifications\Notifiable;

class SomeModel {
    use Notifiable;

    public function routeNotificationForSns($notification)
    {
        return '+1234567890';
    }
}

Event::listen(function (\Illuminate\Notifications\Events\NotificationFailed $event) {
    //Dump and die
    dd($event);
    
    //or log the event
    Log::error('SNS error', $event->data)
});