nextsms / laravel
This package makes it easy to send notifications via NextSMS with Laravel
Fund package maintenance!
alphaolomi
Requires
- php: >=7.4
- illuminate/notifications: ~7.0 || ~8.0 || ~9.0
- illuminate/support: ~7.0 || ~8.0 || ~9.0
- nextsms/php-client: dev-main
Requires (Dev)
- mockery/mockery: ^1.4
- orchestra/testbench: ~5.0 || ~6.0
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.4
README
This package makes it easy to send notifications using NextSMS with Laravel.
Contents
- About
- Laravel compatibly
- Installation
- Setting up the NextSMS service
- Usage
- Testing
- Security
- Contributing
- Credits
- License
About
The NextSMS channel makes it possible to send out Laravel notifications as SMS
using NextSMS API.
Laravel compatibly
Package is Laravel v8 compatible
Installation
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.
Setting up the NextSMS service
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; } }
Usage
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'); } }
Alternative usage
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' ]);
Testing
composer test
Security
If you discover any security-related issues, please email alphaolomi at gmail.com instead of using the issue tracker.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
How do I say Thank you?
Leave a ⭐ star and follow me on Twitter .