This is a Laravel 5 Package for SMS Gateway Integration. This package supports Laravel 5.2 or Higher
. Now Sending SMS is easy.
List of supported gateways:
- Textlocal
- Twilio
- LINK Mobility
- Others are under way.
Older version support (Laravel 5.1) is coming soon.
Via Composer
$ composer require tzsk/sms
In your config/app.php
file add these two lines.
# In your providers array.
'providers' => [
...
Tzsk\Sms\Provider\SmsServiceProvider::class,
],
# In your aliases array.
'aliases' => [
...
'Sms' => Tzsk\Sms\Facade\Sms::class,
],
Now run php artisan vendor:publish
to publish config/sms.php
file in your config directory.
In the config file you can set the default driver to use for all your SMS. But you can also change the driver at runtime.
Textlocal is added by default. You just have to change the creadentials in the textlocal
driver section.
In case you want to use Twilio. Then you have to pull a composer library first.
composer require twilio/sdk
Then you just have to change the creadentials in the twilio
driver section.
In your code just use it like this.
# On the top of the file.
use Tzsk\Sms\Facade\Sms;
...
# In your Controller.
Sms::send("Text to send.", function($sms) {
$sms->to(['Number 1', 'Number 2']); # The numbers to send to.
});
# If you want to use a different driver.
Sms::with('driver name')->send("Text to send.", function($sms) {
$sms->to(['Number 1', 'Number 2']);
});
# Here driver name is explicit : 'twilio' or 'textlocal'.
First you have to name your driver in the drivers array and also you can specify any config params you want.
'drivers' => [
'textlocal' => [...],
'twilio' => [...],
'my_driver' => [
... # Your Config Params here.
]
]
Now you have to create a Driver Map Class that will be used to send the SMS. In your driver, You havet to extend Tzsk\Sms\Drivers\MasterDriver
and also implement Tzsk\Sms\Contract\SendSmsInterface
.
Ex. You careated a class : App\Packages\SMSDriver\MyDriver
.
namespace App\Packages\SMSDriver;
use Tzsk\Sms\Contract\SendSmsInterface;
use Tzsk\Sms\Drivers\MasterDriver;
class MyDriver extends MasterDriver implements SendSmsInterface {
# You will have to make 4 methods of them 2 are created in the Master Driver. You can override if you want.
/**
* 1. __constructor($settings) # {Mandatory} This settings is your Config Params that you've set.
* 2. to($numbers) # (Optional) This is the numbers of the recipient. Can eiter be array or string.
* 3. message($message) # (Optional) This is the message text if they want to change on the fly.
* 4. send() # (Mandatory) This is the main message that will be sent.
*
* If you just create __construct() & send() and don't override to() & message()
* then you will have access to $this->recipients & $this->body inside your send() method.
* Example Given below:
*/
protected $settings = null;
protected $client = null;
public function __construct($settings) {
$this->settings = (object) $settings;
# Initialize any Client that you want.
$this->client = new Client(); # Guzzle Client for example.
}
public function send() {
$this->recipients; # Array of Recipients.
$this->body; # SMS Body.
# Main logic of Sending SMS.
...
}
}
Once you crate that class you have to specify it in the sms.php
Config file map
section.
'map' => [
...
'my_driver' => App\Packages\SMSDriver\MyDriver::class,
]
Note:- You have to make sure that the key of the map
array is identical to the key of the drivers
array.
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email mailtokmahmed@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.