isurindu / laravel-sms
Simple SMS Package for laravel
1.7.5
2021-08-23 11:22 UTC
Requires
- guzzlehttp/guzzle: ^6.5.5|^7.0.1
- shoutoutlabs/shoutout-sdk: ^3.0
README
Support Gateways
- shoutout
- dialog
- mobitel (coming soon)
Installation
You can install the package via composer:
composer require isurindu/laravel-sms
In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php
file:
'providers' => [ // ... Isurindu\LaravelSms\LaravelSmsServiceProvider::class, ];
You can publish config
php artisan vendor:publish --provider="Isurindu\LaravelSms\LaravelSmsServiceProvider::class"
configaration in config/sms.php
return [ 'default_sms_provider'=>env('SMS_PROVIDER', 'dialog'),//dialog,shoutout,log 'fallback_sms_provider'=>env('SMS_PROVIDER_FALLBACK', ''), //alternative sms provider for an emergency 'shoutout'=>[ 'api_key'=>env('SHOUTOUT_API_KEY', 'XXXXXXXXX.XXXXXXXXX.XXXXXXXXX'), 'from'=>env('SHOUTOUT_FROM_NUMBER', 'YOUR_NUMBER_MASK_HERE'), ], 'dialog'=>[ 'username'=>env('DIALOG_USERNAME', ''), 'password'=>env('DIALOG_PASSWORD', ''), 'from'=>env('DIALOG_FROM_NUMBER', 'YOUR_NUMBER_MASK_HERE'), ], ];
Usage
<?php use Isurindu\LaravelSms\Facades\Sms; Sms::to('94702125238') ->send('hello world');
Add New SMS Gateway
Sms::provider('mobitel') ->to('94702125238') ->send('hello world');
if provider is mobitel class name must be located at Gateways\MobitelGateway
<?php namespace Isurindu\LaravelSms\Gateways; use Isurindu\LaravelSms\Interfaces\SmsInterface; use Isurindu\LaravelSms\Exceptions\LaravelSmsGatewayException; class MobitelGateway implements SmsInterface { public function sendSms($to, $msg, $from) { //send sms logic here //if something went wrong throw new LaravelSmsGatewayException('something went wrong'); } }