PHP code example of elimuswift / sms

1. Go to this page and download the library: Download elimuswift/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/ */

    

elimuswift / sms example snippets


	Elimuswift\SMS\Providers\SmsServiceProvider::class,

'SMS' => Elimuswift\SMS\Facades\SMS::class,

'driver' => env('SMS_DRIVER', 'africastalking'),
'africastalking' => [
        'api_key' => env('AT_API_KEY', 'africastalking.api_key'),
        'username' => env('AT_USERNAME', 'africastalking.username'),
    ]

    return [
        'driver' => 'nexmo',
        'from' => 'Company Name',
        'nexmo' => [
            'api_key'       => 'Your Nexmo API Key',
            'api_secret'    => 'Your Nexmo API Secret',
            'encoding'      => 'unicode', // Can be `unicode` or `gsm`
        ]
    ]; 

    return [
        'driver' => 'twilio',
        'from' => '+15555555555', //Your Twilio Number in E.164 Format.
        'twilio' => [
            'account_sid' => 'Your SID',
            'auth_token' => 'Your Token',
            'verify' => true,  //Used to check if messages are really coming from Twilio.
        ]
    ];


use Elimuswift\SMS\Facades\SMS;

SMS::send('My first SMS message', [], function ($sms) {
	$sms->to('07xxxxxxxx');
}); 


use Elimuswift\SMS\Facades\SMS;
$contacts = ['0711xxxxxx', '0722xxxxxx', '0701xxxxxx'];

SMS::send('My bulk SMS notification', [], function ($sms) use($contacts) {
	return array_map(function ($to) use($sms) {
		$sms->to($to);
	}, $contacts);	
}); 


use App\Order;

$order = Order::with('user')->first();

SMS::send('sms.order-shiped', compact('order'), function($sms) use($order) {
    $sms->to($order->user->phone_number);
});

//Will send through default provider set in the config file.
SMS::send('Your SMS Message', [], function($sms) {
    $sms->to('+15555555555');
});

SMS::driver('nexmo');

//Will send through Nexmo
SMS::send('Your SMS Message', [], function($sms) {
    $sms->to('+15555555555');
});

    /**
     * Get the notification identifier for SMS.
     *
     * @return string
     */
    public function routeNotificationForSMS()
    {
        return $this->attributes['phone_number'];
    }

use Elimuswift\SMS\Chennels\SMSChannel;
use Elimuswift\SMS\Notifications\SMSMessage;
use Illuminate\Notifications\Notification;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [SMSChannel::class];
    }

    public function toSms($notifiable)
    {
        return (new SMSMessage())
            ->content("Your {$notifiable->service} account was approved!");
    }
}


public function toSms($notifiable)
{
    return (new SMSMessage('path.to.view'))
         ->viewData(['foo' => 'Bar', 'baaz' => 'blah']);
}