PHP code example of ankurk91 / bandwidth-notification-channel

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

    

ankurk91 / bandwidth-notification-channel example snippets




namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use NotificationChannels\Bandwidth\BandwidthChannel;
use NotificationChannels\Bandwidth\BandwidthMessage;

class AccountApproved extends Notification implements ShouldQueue
{
    use Queueable;
      
    public function via($notifiable): array
    {
        return [BandwidthChannel::class];
    }
  
    public function toBandwidth($notifiable): BandwidthMessage
    {
        return BandwidthMessage::create()
            ->content("Hi {$notifiable->name}, Your account is approved!");
    }
}



namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;
      
    public function routeNotificationForBandwidth($notification)
    {
        return $this->phone_number;
    }
}


use NotificationChannels\Bandwidth\BandwidthMessage;

BandwidthMessage::create()
            ->content("This is sample text message.")
            ->from('+19195551212')
            ->media([
                'https://example.com/a-public-image.jpg',
                'https://example.com/a-public-audio.mp3',
            ])
            ->httpBody([
                'tag' => 'info'         
            ]);



namespace App\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    protected $listen = [
        \Illuminate\Notifications\Events\NotificationSent::class => [
           // \App\Listeners\BandwidthNotificationSent::class,
        ],
        \Illuminate\Notifications\Events\NotificationFailed::class => [
            \App\Listeners\BandwidthNotificationFailed::class,
        ],
    ];   
}



namespace App\Listeners;

use App\Models\User;
use Illuminate\Contracts\Queue\ShouldQueue;
use NotificationChannels\Bandwidth\BandwidthChannel;
use Illuminate\Notifications\Events\NotificationFailed;

class BandwidthNotificationFailed implements ShouldQueue
{
    public function handle(NotificationFailed $event)
    {
        if ($event->channel !== BandwidthChannel::class) {
            return;
        }

        /** @var User $user */
        $user = $event->notifiable;
        
        // todo Do something with $user
    }
}

use Illuminate\Support\Facades\Notification;
use App\Notification\ExampleSMSNotification;

Notification::route('Bandwidth', '+1234567890')   
    ->notify(new ExampleSMSNotification());
bash
php artisan vendor:publish --provider="NotificationChannels\Bandwidth\BandwidthServiceProvider" --tag="config"