PHP code example of laravel-notification-channels / africastalking

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


'africastalking' => [
    'username'      => env('AT_USERNAME'),
    'key'           => env('AT_KEY'),
    'from'          => env('AT_FROM'),
]



namespace App;

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

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Route notifications for the Africas Talking channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
     */
    public function routeNotificationForAfricasTalking($notification)
    {
        return $this->phone_number;
    }
}



use NotificationChannels\AfricasTalking\AfricasTalkingChannel;
use NotificationChannels\AfricasTalking\AfricasTalkingMessage;

class NewsWasPublished extends Notification
{

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

    public function toAfricasTalking($notifiable)
    {
		return (new AfricasTalkingMessage())
                    ->content('Your SMS message content');

    }
}
 php
        return (new AfricasTalkingMessage())
                    ->content("Your SMS message content")
                    ->to("put the recipient phone number here"); //eg ->to(1111111111)
 php
        return (new AfricasTalkingMessage())
                    ->content("Your SMS message content")
                    ->to("put the recipient phone number here"); //eg ->to(11111111)