1. Go to this page and download the library: Download saber13812002/sms library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
# On the top of the file.
use Tzsk\Sms\Facades\Sms;
...
# In your Controller.
Sms::send("this message", function($sms) {
$sms->to(['Number 1', 'Number 2']); # The numbers to send to.
});
# OR...
Sms::send("this message")->to(['Number 1', 'Number 2'])->dispatch();
# If you want to use a different driver.
Sms::via('gateway')->send("this message", function($sms) {
$sms->to(['Number 1', 'Number 2']);
});
# OR...
Sms::via('gateway')->send("this message")->to(['Number 1', 'Number 2'])->dispatch();
# Here gateway is explicit : 'twilio' or 'textlocal' or any other driver in the config.
# The numbers can be a single string as well.
# If you are not a Laravel's facade fan, you can use sms helper:
sms()->send("this message", function($sms) {
$sms->to(['Number 1', 'Number 2']); # The numbers to send to.
});
sms()->send("this message")->to(['Number 1', 'Number 2'])->dispatch();
sms()->via('gateway')->send("this message", function($sms) {
$sms->to(['Number 1', 'Number 2']);
});
sms()->via('gateway')->send("this message")->to(['Number 1', 'Number 2'])->dispatch();
namespace App\Notifications;
use Tzsk\Sms\Builder;
use Illuminate\Bus\Queueable;
use Tzsk\Sms\Channels\SmsChannel;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
class InvoicePaid extends Notification
{
use Queueable;
/**
* Get the notification channels.
*
* @param mixed $notifiable
* @return array|string
*/
public function via($notifiable)
{
return [SmsChannel::class];
}
/**
* Get the repicients and body of the notification.
*
* @param mixed $notifiable
* @return Builder
*/
public function toSms($notifiable)
{
return (new Builder)->via('gateway') # via() is Optional
->send('this message')
->to('some number');
}
}
$builder = (new Builder)->via('gateway') # via() is Optional
->send('this message')
->to('some number');
Sms::send($builder);
# OR...
$builder = (new Builder)->send('this message')
->to(['some number']);
Sms::via('gateway')->send($builder);
namespace App\Packages\SMSDriver;
use Tzsk\Sms\Contracts\Driver;
class MyDriver extends Driver
{
# You will have to make 2 methods.
/**
* 1. __constructor($settings) # {Mandatory} This settings is your Config Params that you've set.
* 2. send() # (Mandatory) This is the main message that will be sent.
*
* Example Given below:
*/
/**
* @var array
*/
protected $settings;
/**
* @var mixed
*/
protected $client;
/**
* Your Driver Config.
*
* @var array $settings
*/
public function __construct($settings)
{
$this->settings = $settings;
# Initialize any Client that you want.
$this->client = new Client(); # Guzzle Client for example.
}
/**
* @return object Ex.: (object) ['status' => true, 'data' => 'Client Response Data'];
*/
public function send()
{
$this->recipients; # Array of Recipients.
$this->body; # SMS Body.
# Main logic of Sending SMS.
...
}
}