This package makes it easy to send notifications using Nigeriabulksms with Laravel 5 and above
- About
- Installation
- Setting up the Nigeriabulksms service
- Usage
- Security
- Contributing
- Credits
- License
This package makes it possible to send out Laravel notifications as a SMS
using Nigeriabulksms API.
You can install this package via composer:
composer require ossycodes/nigeriabulksms
The service provider gets loaded automatically.
You will need to Register to get your username and password
. Place them inside your .env
file. Remember to add your Sender ID that you will be using to send the messages.
NIGERIABULKSMS_USERNAME=""
NIGERIABULKSMS_PASSWORD=""
NIGERIABULKSMS_SENDER=""
To load them, add this to your config/services.php
. This will load the Nigeriabulksms data from the .env
file.file:
'nigeriabulksms' => [
'username' => env('NIGERIABULKSMS_USERNAME'),
'password' => env('NIGERIABULKSMS_PASSWORD'),
'sender' => env('NIGERIABULKSMS_SENDER'),
]
Add the routeNotifcationForNigeriabulksms
method on your notifiable Model.
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* Route notifications for the Nigeriabulksms channel.
*
* @param \Illuminate\Notifications\Notification $notification
* @return string
*/
public function routeNotificationForNigeriabulksms($notification)
{
return $this->phone;
}
}
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.
<?php
use NotificationChannels\Nigeriabulksms\NigeriabulksmsChannel;
use NotificationChannels\Nigeriabulksms\NigeriabulksmsMessage;
class NewsWasPublished extends Notification
{
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [NigeriabulksmsChannel::class];
}
public function toNigeriabulksms($notifiable)
{
return (new NigeriabulksmsMessage())
->setContent('Your SMS message content');
}
}
Additionally you can add recipients(the phonenumber the messages will be sent to) (single value or array)
return (new NigeriabulksmsMessage("Your {$notifiable->service} was ordered!"))->setRecipients($recipients);
also you can add who the notification(sms) is sent from, this will overide the NIGERIABULKSMS_SENDER="" in your .env
return (new NigeriabulksmsMessage("Your {$notifiable->service} was ordered!"))->setFrom("name of your app");
Incase of errors from Nigeriabulksms service please do well to check Nigeriabulksms api error codes on thier developer portal
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.
Leave a star and follow me on Twitter .