Download the PHP package diereysaa/laravel-sms-api without Composer
On this page you can find all versions of the php package diereysaa/laravel-sms-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download diereysaa/laravel-sms-api
More information about diereysaa/laravel-sms-api
Files in diereysaa/laravel-sms-api
Package laravel-sms-api
Short Description Laravel package to provide SMS API integration. Any SMS vendor that provides REST API can be used. SMS-API channel for Laravel notifications also included.
License MIT
Homepage https://github.com/gr8shivam/laravel-sms-api
Informations about the package laravel-sms-api
Integrate SMS API with Laravel
Laravel package to provide SMS API integration. Any SMS vendor that provides REST API can be used.
Star ⭐ repo to show suport 😊
Installation
Install Package
Require this package with composer:
Add Service Provider & Facade
For Laravel 5.5+
Once the package is added, the service provider and facade will be autodiscovered.
For Older versions of Laravel
Add the ServiceProvider to the providers array in config/app.php
:
Add the Facade to the aliases array in config/app.php
:
Publish Config
Once done, publish the config to your config folder using:
Configuration
Once the config file is published, open config/sms-api.php
Global config
country_code
: The default country code to be used
default
: Default gateway
Gateway Config
Use can define multiple gateway configs like this:-
Special Parameters in Gateway Config
json
Parameter
The json
parameter accepts true/false
. When true
, it sends params
as a JSON payload. It also takes care of 'Content-Type' => 'application/json'
header.
jsonToArray
Parameter
The jsonToArray
parameter accepts true/false
. When true
, it sends a single mobile number in an encapsulated array in the JSON payload. When false
, a single mobile number is sent as text. Valid only when json
parameter is true
.
wrapper
Parameter
The wrapper
is a special parameter which will be required only with some gateways. It wraps the JSON payload in the following structure:
wrapperParams
Parameter
Accepts array. Used to add custom Wrapper Parameters. Parameters can also be added while calling the smsapi()
function like smsapi()->addWrapperParams(['wrapperParam1'=>'paramVal'])->sendMessage("TO", "Message")
Usage
Direct Use
Use the smsapi()
helper function or SmsApi
facade to send the messages.
TO
: Single mobile number or Multiple comma-separated mobile numbers
MESSAGE
: Message to be sent
Using Helper function
-
Basic Usage
smsapi("TO", "Message");
orsmsapi()->sendMessage("TO","MESSAGE");
-
Adding extra parameters
smsapi("TO", "Message", ["param1" => "val"]);
orsmsapi()->sendMessage("TO", "Message", ["param1" => "val"]);
-
Adding extra headers
smsapi("TO", "Message", ["param1" => "val"], ["header1" => "val"]);
orsmsapi()->sendMessage("TO", "Message", ["param1" => "val"], ["header1" => "val"]);
-
Using a different gateway
smsapi()->gateway('GATEWAY_NAME')->sendMessage("TO", "Message");
-
Using a different country code
smsapi()->countryCode('COUNTRY_CODE')->sendMessage("TO", "Message");
- Sending message to multiple mobiles
smsapi(["Mobile1","Mobile2","Mobile3"], "Message");
orsmsapi()->sendMessage(["Mobile1","Mobile2","Mobile3"],"MESSAGE");
Using SmsApi facade
-
Basic Usage
SmsApi::sendMessage("TO","MESSAGE");
-
Adding extra parameters
SmsApi::sendMessage("TO", "Message", ["param1" => "val"]);
-
Adding extra headers
SmsApi::sendMessage("TO", "Message", ["param1" => "val"], ["header1" => "val"]);
-
Using a different gateway
SmsApi::gateway('GATEWAY_NAME')->sendMessage("TO", "Message");
-
Using a different country code
SmsApi::countryCode('COUNTRY_CODE')->sendMessage("TO", "Message");
- Sending message to multiple mobiles
SmsApi::sendMessage(["Mobile1","Mobile2","Mobile3"],"MESSAGE");
Use in Notifications
Setting up the Route for Notofication
Add the method routeNotificationForSmsApi()
to your Notifiable model :
By default, your User model uses Notifiable.
Setting up Notification
Add
use Gr8Shivam\SmsApi\Notifications\SmsApiChannel;
and
use Gr8Shivam\SmsApi\Notifications\SmsApiMessage;
to your notification.
You can create a new notification with php artisan make:notification NOTIFICATION_NAME
In the via
function inside your notification, add return [SmsApiChannel::class];
and add a new function toSmsApi($notifiable)
to return the message body and parameters.
Notification example:-
You can also use ->params(["param1" => "val"])
to add extra parameters to the request and ->headers(["header1" => "val"])
to add extra headers to the request.
Getting Response
You can get response by using ->response()
or get the Response Code using ->getResponseCode()
. For example, smsapi()->sendMessage("TO","MESSAGE")->response();
Support
Feel free to post your issues in the issues section.
Credits
Developed by Shivam Agarwal
Thanks to laravel-ovh-sms & softon-sms
License
MIT
All versions of laravel-sms-api with dependencies
illuminate/support Version ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
guzzlehttp/guzzle Version ~6.0|^7.0