Skip to content


Switch branches/tags

Latest commit

…highest priority (#18)

* if to() method is used to set the recipient phonenumber, then it has the highest priority

* wip

Git stats


Failed to load latest commit information.
Latest commit message
Commit time

AfricasTalking notification channel for Laravel

Latest Version on Packagist Software License StyleCI Quality Score Total Downloads

This package makes it easy to send notifications using AfricasTalking with Laravel.



This package is part of the Laravel Notification Channels project. It provides additional Laravel Notification channels to the ones given by Laravel itself.

The AfricasTalking channel makes it possible to send out Laravel notifications as a SMS using AfricasTalking API.


You can install this package via composer:

composer require laravel-notification-channels/africastalking

The service provider gets loaded automatically.

Setting up the AfricasTalking service

You will need to Register and then go to your sandbox app Go To SandBox App. Click on settings Within this page, you will generate your Username and key. Place them inside your .env file. Remember to add your Sender ID that you will be using to send the messages.

Please note if you do not have a VALID sender_ID remove "AT_FROM" from your .env or leave it as ""

AT_FROM="" // please note if you do not have a valid sender_ID remove this or leave it as ""

To load them, add this to your config/services.php . This will load the AfricasTalking data from the .env file.file:

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

Add the routeNotifcationForAfricasTalking method on your notifiable Model. If this is not added, the phone_number field will be automatically used.


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;


To use this package, you need to create a notification class, like NewsWasPublished from the example below, in your Laravel application. Make sure to check out Laravel's documentation for this process.


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');


You can also modify who the notification(SMS) is sent from, this will overide the AT_FROM= in your .env Please only do this if you have a VALID sender_ID

        return (new AfricasTalkingMessage())
                    ->content('Your SMS message content')
                    ->from("set any sender id/name here");

You can also modify who the notification(SMS) is sent to (the recipient)

        return (new AfricasTalkingMessage())
                    ->content('Your SMS message content')
                    ->to("put the recipient phonenumber here"); //eg ->to(1111111111)

It's important to know the Order in which the recipient phone number the notification(SMS) will be sent to will be used

  1. If you have defined the routeNotificationForAfricasTalking() method on the Notifiable class (User.php in this case) and returned a valid phone number, then that will be used.

  2. if you did not define routeNotificationForAfricasTalking() method on the Notifiable class (User.php in this case), then the phone_number attribute of the User will be used ($user->phone_number)

  3. Lastly if the recipient phone number is set using ->to(1111111), this will overide the phone number provided in either 1 or 2.

        return (new AfricasTalkingMessage())
                    ->content('Your SMS message content')
                    ->to("put the recipient phonenumber here"); //eg ->to(11111111)


$ composer test


If you discover any security-related issues, please email instead of using the issue tracker.


Please see CONTRIBUTING for details.



The MIT License (MIT). Please see License File for more information.

How do I say Thank you?

Please buy me a cup of coffee , Leave a star and follow me on Twitter .