This package makes it easy to send notifications using NextSMS with Laravel.
- About
- Laravel compatibly
- Installation
- Setting up the NextSMS service
- Usage
- Testing
- Security
- Contributing
- Credits
- License
The NextSMS channel makes it possible to send out Laravel notifications as SMS
using NextSMS API.
Package is Laravel v8 compatible
Laravel Version | Package Version | Notes |
---|---|---|
v7 or v8 | dev-main | Latest version |
v6 | 6.0.x-dev | |
v5 | 5.x-dev |
You can install this package via composer:
This will install the latest version
composer require nextsms/laravel
To install previous version of the package eg: version 6.0.x-dev compatible with laravel v6 see
composer require nextsms/laravel:6.0.x-dev
The service provider gets loaded automatically.
You will need to Register.
Remember to add your Sender ID that you will be using to send the messages.
NEXTSMS_USERNAME=""
NEXTSMS_PASSWORD=""
NEXTSMS_FROM=""
NEXTSMS_ENVIROMENT="production"
You can publish the package configuration file:
php artisan vendor:publish --provider="NotificationChannels\NextSms\NextSmsServiceProvider" --tag="config"
Add the routeNotifcationForNextSms
method on your notifiable Model. If this is not added,
the phone_number
field will be automatically used.
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* Route notifications for the NextSMS channel.
*
* @param \Illuminate\Notifications\Notification $notification
* @return string
*/
public function routeNotificationForNextSms($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\NextSms\NextSmsChannel;
use NotificationChannels\NextSms\NextSmsMessage;
class NewsWasPublished extends Notification
{
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [NextSmsChannel::class];
}
public function toNextSms($notifiable)
{
return (new NextSmsMessage())
->content('Your SMS message content');
}
}
This packages comes with a Facade portating the NextSmsService
this is usefull of you onyl want to send SMS without dealing the the Laravel Notification system
See full list of API avaliable
// import this
use NotificationChannels\NextSms\NextSmsFacade as NextSms;
// in your controller
NextSms::singleDestination([
'from' => 'NEXTSMS',
'to' => '255716718040',
'text' => 'Your message'
]);
composer test
If you discover any security-related issues, please email alphaolomi at gmail.com 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 .